INTL_ICU_VERSION
(string)
INTL_MAX_LOCALE_LEN
(integer)
IDNA_DEFAULT
(integer)
IDNA_ALLOW_UNASSIGNED
(integer)
IDNA_USE_STD3_RULES
(integer)
IDNA_CHECK_BIDI
(integer)
IDNA_CHECK_CONTEXTJ
(integer)
IDNA_NONTRANSITIONAL_TO_ASCII
(integer)
IDNA_NONTRANSITIONAL_TO_UNICODE
(integer)
INTL_IDNA_VARIANT_2003
(integer)
INTL_IDNA_VARIANT_UTS46
(integer)
IDNA_ERROR_EMPTY_LABEL (integer)
IDNA_ERROR_LABEL_TOO_LONG (integer)
IDNA_ERROR_DOMAIN_NAME_TOO_LONG (integer)
IDNA_ERROR_LEADING_HYPHEN (integer)
IDNA_ERROR_TRAILING_HYPHEN (integer)
IDNA_ERROR_HYPHEN_3_4 (integer)
IDNA_ERROR_LEADING_COMBINING_MARK
(integer)
IDNA_ERROR_DISALLOWED (integer)
IDNA_ERROR_PUNYCODE (integer)
IDNA_ERROR_LABEL_HAS_DOT (integer)
IDNA_ERROR_INVALID_ACE_LABEL (integer)
IDNA_ERROR_BIDI (integer)
IDNA_ERROR_CONTEXTJ (integer)
Each module provides two kind of APIs: a procedural one and an object oriented one. Both are actually identical and described in the corresponding document.
Note:
All input strings must be in UTF-8 encoding. All output strings are also in UTF-8.
Example #1 Example of using the procedural API
<?php
$coll = collator_create('en_US');
$result = collator_compare($coll, "string#1", "string#2");
?>
Example #2 Example of using the object-oriented API
<?php
$coll = new Collator('en_US');
$al = $coll->getLocale(Locale::ACTUAL_LOCALE);
echo "Actual locale: $al\n";
$formatter = new NumberFormatter('en_US', NumberFormatter::DECIMAL);
echo $formatter->format(1234567);
?>
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Provides string comparison capability with support for appropriate locale-sensitive sort orderings.
Collator::FRENCH_COLLATION
(integer)
Sort strings with different accents from the back of the string. This attribute is automatically set to On for the French locales and a few others. Users normally would not need to explicitly set this attribute. There is a string comparison performance cost when it is set On, but sort key length is unaffected. Possible values are:
Collator::ONCollator::OFF(default)Collator::DEFAULT_VALUE
Example #1 FRENCH_COLLATION rules
Collator::ALTERNATE_HANDLING
(integer)
The Alternate attribute is used to control the handling of the so called variable characters in the UCA: whitespace, punctuation and symbols. If Alternate is set to NonIgnorable (N), then differences among these characters are of the same importance as differences among letters. If Alternate is set to Shifted (S), then these characters are of only minor importance. The Shifted value is often used in combination with Strength set to Quaternary. In such a case, whitespace, punctuation, and symbols are considered when comparing strings, but only if all other aspects of the strings (base letters, accents, and case) are identical. If Alternate is not set to Shifted, then there is no difference between a Strength of 3 and a Strength of 4. For more information and examples, see Variable_Weighting in the » UCA. The reason the Alternate values are not simply On and Off is that additional Alternate values may be added in the future. The UCA option Blanked is expressed with Strength set to 3, and Alternate set to Shifted. The default for most locales is NonIgnorable. If Shifted is selected, it may be slower if there are many strings that are the same except for punctuation; sort key length will not be affected unless the strength level is also increased.
Possible values are:
Collator::NON_IGNORABLE(default)Collator::SHIFTEDCollator::DEFAULT_VALUE
Example #2 ALTERNATE_HANDLING rules
Collator::CASE_FIRST
(integer)
The Case_First attribute is used to control whether uppercase letters
come before lowercase letters or vice versa, in the absence of other
differences in the strings. The possible values are
Uppercase_First
(U) and Lowercase_First
(L), plus the standard Default
and Off.
There is almost no difference between the Off and Lowercase_First
options in terms of results, so typically users will not use
Lowercase_First: only Off or Uppercase_First. (People interested in the
detailed differences between X and L should consult the Collation
Customization). Specifying either L or U won't affect string comparison
performance, but will affect the sort key length.
Possible values are:
Collator::OFF(default)Collator::LOWER_FIRSTCollator::UPPER_FIRSTCollator:DEFAULT
Example #3 CASE_FIRST rules
Collator::CASE_LEVEL
(integer)
The Case_Level attribute is used when ignoring accents but not case. In such a situation, set Strength to be Primary, and Case_Level to be On. In most locales, this setting is Off by default. There is a small string comparison performance and sort key impact if this attribute is set to be On.
Possible values are:
Collator::OFF(default)Collator::ONCollator::DEFAULT_VALUE
Example #4 CASE_LEVEL rules
Collator::NORMALIZATION_MODE
(integer)
The Normalization setting determines whether text is thoroughly normalized or not in comparison. Even if the setting is off (which is the default for many locales), text as represented in common usage will compare correctly (for details, see UTN #5). Only if the accent marks are in noncanonical order will there be a problem. If the setting is On, then the best results are guaranteed for all possible text input. There is a medium string comparison performance cost if this attribute is On, depending on the frequency of sequences that require normalization. There is no significant effect on sort key length. If the input text is known to be in NFD or NFKD normalization forms, there is no need to enable this Normalization option.
Possible values are:
Collator::OFF(default)Collator::ONCollator::DEFAULT_VALUECollator::STRENGTH
(integer)
The ICU Collation Service supports many levels of comparison (named "Levels", but also known as "Strengths"). Having these categories enables ICU to sort strings precisely according to local conventions. However, by allowing the levels to be selectively employed, searching for a string in text can be performed with various matching conditions. For more detailed information, see collator_set_strength() chapter.
Possible values are:
Collator::PRIMARYCollator::SECONDARYCollator::TERTIARY(default)Collator::QUATERNARYCollator::IDENTICALCollator::DEFAULT_VALUECollator::HIRAGANA_QUATERNARY_MODE
(integer)
Compatibility with JIS x 4061 requires the introduction of an additional level to distinguish Hiragana and Katakana characters. If compatibility with that standard is required, then this attribute should be set On, and the strength set to Quaternary. This will affect sort key length and string comparison string comparison performance.
Possible values are:
Collator::OFF(default)Collator::ONCollator::DEFAULT_VALUECollator::NUMERIC_COLLATION
(integer)
When turned on, this attribute generates a collation key for the numeric value of substrings of digits. This is a way to get '100' to sort AFTER '2'.
Possible values are:
Collator::OFF(default)Collator::ONCollator::DEFAULT_VALUECollator::DEFAULT_VALUE
(integer)
Collator::PRIMARY
(integer)
Collator::SECONDARY
(integer)
Collator::TERTIARY
(integer)
Collator::DEFAULT_STRENGTH
(integer)
Collator::QUATERNARY
(integer)
Collator::IDENTICAL
(integer)
Collator::OFF
(integer)
Collator::ON
(integer)
Collator::SHIFTED
(integer)
Collator::NON_IGNORABLE
(integer)
Collator::LOWER_FIRST
(integer)
Collator::UPPER_FIRST
(integer)
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Collator::asort -- collator_asort — Sort array maintaining index association
Object oriented style
&$arr
[, int $sort_flag
] ) : boolProcedural style
This function sorts an array such that array indices maintain their correlation with the array elements they are associated with. This is used mainly when sorting associative arrays where the actual element order is significant. Array elements will have sort order according to current locale rules.
Equivalent to standard PHP asort().
collCollator object.
arrArray of strings to sort.
sort_flagOptional sorting type, one of the following:
Collator::SORT_REGULAR
- compare items normally (don't change types)
Collator::SORT_NUMERIC
- compare items numerically
Collator::SORT_STRING
- compare items as strings
Default $sort_flag value is
Collator::SORT_REGULAR.
It is also used if an invalid $sort_flag value has been specified.
Returns TRUE on success or FALSE on failure.
Example #1 collator_asort()example
<?php
$coll = collator_create( 'en_US' );
$arr = array(
'a' => '100',
'b' => '50',
'c' => '7'
);
collator_asort( $coll, $arr, Collator::SORT_NUMERIC );
var_export( $arr );
collator_asort( $coll, $arr, Collator::SORT_STRING );
var_export( $arr );
?>
The above example will output:
array (
'c' => '7',
'b' => '50',
'a' => '100',
)array (
'a' => '100',
'b' => '50',
'c' => '7',
)
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Collator::compare -- collator_compare — Compare two Unicode strings
Object oriented style
$str1
, string $str2
) : intProcedural style
Compare two Unicode strings according to collation rules.
collCollator object.
str1The first string to compare.
str2The second string to compare.
Return comparison result:
1 if str1 is greater than
str2 ;
0 if str1 is equal to
str2;
-1 if str1 is less than
str2 .
FALSE
is returned.
This function may
return Boolean FALSE, but may also return a non-Boolean value which
evaluates to FALSE. Please read the section on Booleans for more
information. Use the ===
operator for testing the return value of this
function.
Example #1 collator_compare()example
<?php
$s1 = 'Hello';
$s2 = 'hello';
$coll = collator_create( 'en_US' );
$res = collator_compare( $coll, $s1, $s2 );
if ($res === false) {
echo collator_get_error_message( $coll );
} else if( $res > 0 ) {
echo "s1 is greater than s2\n";
} else if( $res < 0 ) {
echo "s1 is less than s2\n";
} else {
echo "s1 is equal to s2\n";
}
?>
The above example will output:
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Collator::__construct — Create a collator
$locale
)Creates a new instance of Collator.
localeThe locale whose collation rules should be used. Special values for locales can be passed in - if null is passed for the locale, the default locale's collation rules will be used. If "root" is passed, UCA rules will be used.
The Locale attribute is typically the most important attribute for correct sorting and matching, according to the user expectations in different countries and regions. The default » UCA ordering will only sort a few languages such as Dutch and Portuguese correctly ("correctly" meaning according to the normal expectations for users of the languages). Otherwise, you need to supply the locale to UCA in order to properly collate text for a given language. Thus a locale needs to be supplied so as to choose a collator that is correctly tailored for that locale. The choice of a locale will automatically preset the values for all of the attributes to something that is reasonable for that locale. Thus most of the time the other attributes do not need to be explicitly set. In some cases, the choice of locale will make a difference in string comparison performance and/or sort key length.
Returns Collator instance.
Returns an "empty" object on error. You can use intl_get_error_code() and/or intl_get_error_message() to know what happened.
Example #1 Collator::__construct() example
<?php
$coll = new Collator( 'en_CA' );
?>
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Collator::create -- collator_create — Create a collator
Object oriented style
Procedural style
The strings will be compared using the options already specified.
localeThe locale containing the required collation rules. Special values for locales can be passed in - if null is passed for the locale, the default locale collation rules will be used. If empty string ("") or "root" are passed, » UCA rules will be used.
Return new instance of Collator object, or NULL
on error.
Example #1 collator_create() example
<?php
$coll = collator_create( 'en_US' );
if( !isset( $coll ) ) {
printf( "Collator creation failed: %s\n", intl_get_error_message() );
exit( 1 );
}
?>
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Collator::getAttribute -- collator_get_attribute — Get collation attribute value
Object oriented style
$attr
) : intProcedural style
Get a value of an integer collator attribute.
Attribute value, or boolean FALSE on error.
Example #1 collator_get_attribute() example
<?php
$coll = collator_create( 'en_CA' );
$val = collator_get_attribute( $coll, Collator::NUMERIC_COLLATION );
if( $val === false )
{
// Handle error.
}
?>
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Collator::getErrorCode -- collator_get_error_code — Get collator's last error code
Object oriented style
Procedural style
Error code returned by the last Collator API function call.
Example #1 collator_get_error_code() example
<?php
$coll = collator_create( 'en_US' );
if( collator_get_attribute( $coll, Collator::FRENCH_COLLATION ) === false )
handle_error( collator_get_error_code() );
?>
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Collator::getErrorMessage -- collator_get_error_message — Get text for collator's last error code
Object oriented style
Procedural style
Retrieves the message for the last error.
Description of an error occurred in the last Collator API function call.
Example #1 collator_get_error_message() example
<?php
$coll = collator_create( 'lt' );
if( collator_compare( $coll, 'y', 'k' ) === false ) {
echo collator_get_error_message( $coll );
}
?>
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Collator::getLocale -- collator_get_locale — Get the locale name of the collator
Object oriented style
$type
) : stringProcedural style
Get collector locale name.
collCollator object.
type
You can choose between valid and actual locale (
Locale::VALID_LOCALE and
Locale::ACTUAL_LOCALE,
respectively).
Real locale name from which the collation data comes. If the collator was
instantiated from rules or an error occurred, returns
boolean FALSE.
Example #1 collator_get_locale() example
<?php
$coll = collator_create( 'en_US_California' );
$res_val = collator_get_locale( $coll, Locale::VALID_LOCALE );
$res_act = collator_get_locale( $coll, Locale::ACTUAL_LOCALE );
printf( "Valid locale name: %s\nActual locale name: %s\n",
$res_val, $res_act );
?>
The above example will output:
Requested locale name: en_US_California Valid locale name: en_US Actual locale name: en
(PHP 5 >= 5.3.2, PHP 7, PECL intl >= 1.0.3)
Collator::getSortKey -- collator_get_sort_key — Get sorting key for a string
Object oriented style
$str
) : stringProcedural style
Return collation key for a string. Collation keys can be compared directly instead of strings, though are implementation specific and may change between ICU library versions. Sort keys are generally only useful in databases or other circumstances where function calls are extremely expensive.
Returns the collation key for the string, or FALSE on failure.
This function may
return Boolean FALSE, but may also return a non-Boolean value which
evaluates to FALSE. Please read the section on Booleans for more
information. Use the ===
operator for testing the return value of this
function.
| Version | Description |
|---|---|
| 5.3.15, 5.4.5 |
Sort keys do no longer contain any NUL bytes.
|
Example #1 collator_get_sort_key()example
<?php
$s1 = 'Hello';
$coll = collator_create('en_US');
$res = collator_get_sort_key($coll, $s1);
echo bin2hex($res);
?>
The above example will output something similar to:
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Collator::getStrength -- collator_get_strength — Get current collation strength
Object oriented style
Procedural style
Returns current collation strength, or boolean FALSE on error.
Example #1 collator_get_strength() example
<?php
$coll = collator_create( 'en_US' );
$strength = collator_get_strength( $coll );
?>
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Collator::setAttribute -- collator_set_attribute — Set collation attribute
Object oriented style
$attr
, int $val
) : boolProcedural style
Returns TRUE on success or FALSE on failure.
Example #1 collator_set_attribute() example
<?php
$coll = collator_create( 'en_CA' );
$val = collator_get_attribute( $coll, Collator::NUMERIC_COLLATION );
if ($val === false) {
// Handle error.
} elseif ($val === Collator::ON) {
// Do something useful.
}
?>
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Collator::setStrength -- collator_set_strength — Set collation strength
Object oriented style
$strength
) : boolProcedural style
The » ICU Collation Service supports many levels of comparison (named "Levels", but also known as "Strengths"). Having these categories enables ICU to sort strings precisely according to local conventions. However, by allowing the levels to be selectively employed, searching for a string in text can be performed with various matching conditions.
Primary Level: Typically, this is used to denote differences between base characters (for example, "a" < "b"). It is the strongest difference. For example, dictionaries are divided into different sections by base character. This is also called the level1 strength.
Secondary Level: Accents in the characters are considered secondary differences (for example, "as" < "às" < "at"). Other differences between letters can also be considered secondary differences, depending on the language. A secondary difference is ignored when there is a primary difference anywhere in the strings. This is also called the level2 strength.
Note:
Note: In some languages (such as Danish), certain accented letters are considered to be separate base characters. In most languages, however, an accented letter only has a secondary difference from the unaccented version of that letter.
Tertiary Level: Upper and lower case differences in characters are distinguished at the tertiary level (for example, "ao" < "Ao" < "aò"). In addition, a variant of a letter differs from the base form on the tertiary level (such as "A" and " "). Another example is the difference between large and small Kana. A tertiary difference is ignored when there is a primary or secondary difference anywhere in the strings. This is also called the level3 strength.
Quaternary Level: When punctuation is ignored (see Ignoring Punctuations ) at level 13, an additional level can be used to distinguish words with and without punctuation (for example, "ab" < "a-b" < "aB"). This difference is ignored when there is a primary, secondary or tertiary difference. This is also known as the level4 strength. The quaternary level should only be used if ignoring punctuation is required or when processing Japanese text (see Hiragana processing).
Identical Level: When all other levels are equal, the identical level is used as a tiebreaker. The Unicode code point values of the NFD form of each string are compared at this level, just in case there is no difference at levels 14. For example, Hebrew cantillation marks are only distinguished at this level. This level should be used sparingly, as only code point values differences between two strings is an extremely rare occurrence. Using this level substantially decreases the performance for both incremental comparison and sort key generation (as well as increasing the sort key length). It is also known as level 5 strength.
For example, people may choose to ignore accents or ignore accents and case when searching for text. Almost all characters are distinguished by the first three levels, and in most locales the default value is thus Tertiary. However, if Alternate is set to be Shifted, then the Quaternary strength can be used to break ties among whitespace, punctuation, and symbols that would otherwise be ignored. If very fine distinctions among characters are required, then the Identical strength can be used (for example, Identical Strength distinguishes between the Mathematical Bold Small A and the Mathematical Italic Small A.). However, using levels higher than Tertiary the Identical strength result in significantly longer sort keys, and slower string comparison performance for equal strings.
collCollator object.
strengthStrength to set.
Possible values are:
Collator::PRIMARY
Collator::SECONDARY
Collator::TERTIARY
Collator::QUATERNARY
Collator::IDENTICAL
Collator::DEFAULT_STRENGTH
Returns TRUE on success or FALSE on failure.
Example #1 collator_set_strength() example
<?php
$arr = array( 'aò', 'Ao', 'ao' );
$coll = collator_create( 'en_US' );
// Sort array using default strength.
collator_sort( $coll, $arr );
var_export( $arr );
// Sort array using primary strength.
collator_set_strength( $coll, Collator::PRIMARY );
collator_sort( $coll, $arr );
var_export( $arr );
?>
The above example will output:
array (
0 => 'ao',
1 => 'Ao',
2 => 'aò',
)
array (
0 => 'aò',
1 => 'Ao',
2 => 'ao',
)
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Collator::sortWithSortKeys -- collator_sort_with_sort_keys — Sort array using specified collator and sort keys
Object oriented style
&$arr
) : boolProcedural style
Similar to collator_sort() but uses ICU sorting keys produced by ucol_getSortKey() to gain more speed on large arrays.
Returns TRUE on success or FALSE on failure.
Example #1 collator_sort_with_sort_keys() example
<?php
$arr = array( 'Köpfe', 'Kypper', 'Kopfe' );
$coll = collator_create( 'sv' );
collator_sort_with_sort_keys( $coll, $arr );
var_export( $arr );
?>
The above example will output:
array (
0 => 'Kopfe',
1 => 'Kypper',
2 => 'Köpfe',
)
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Collator::sort -- collator_sort — Sort array using specified collator
Object oriented style
&$arr
[, int $sort_flag
] ) : boolProcedural style
This function sorts an array according to current locale rules.
Equivalent to standard PHP sort() .
collCollator object.
arrArray of strings to sort.
sort_flagOptional sorting type, one of the following:
Collator::SORT_REGULAR
- compare items normally (don't change types)
Collator::SORT_NUMERIC
- compare items numerically
Collator::SORT_STRING
- compare items as strings
Collator::SORT_REGULAR.
It is also used if an invalid sort_flag value has been specified.
Returns TRUE on success or FALSE on failure.
Example #1 collator_sort() example
<?php
$coll = collator_create( 'en_US' );
$arr = array( 'at', 'às', 'as' );
var_export( $arr );
collator_sort( $coll, $arr );
var_export( $arr );
?>
The above example will output:
array (
0 => 'at',
1 => 'às',
2 => 'as',
)array (
0 => 'as',
1 => 'às',
2 => 'at',
)
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Programs store and operate on numbers using a locale-independent binary representation. When displaying or printing a number it is converted to a locale-specific string. For example, the number 12345.67 is "12,345.67" in the US, "12 345,67" in France and "12.345,67" in Germany.
By invoking the methods provided by the NumberFormatter class, you can format numbers, currencies, and percentages according to the specified or default locale. NumberFormatter is locale-sensitive so you need to create a new NumberFormatter for each locale. NumberFormatter methods format primitive-type numbers, such as double and output the number as a locale-specific string.
For currencies you can use currency format type to create a formatter that returns a string with the formatted number and the appropriate currency sign. Of course, the NumberFormatter class is unaware of exchange rates so, the number output is the same regardless of the specified currency. This means that the same number has different monetary values depending on the currency locale. If the number is 9988776.65 the results will be:
In order to format percentages, create a locale-specific formatter with percentage format type. With this formatter, a decimal fraction such as 0.75 is displayed as 75%.
For more complex formatting, like spelled-out numbers, the rule-based number formatters are used.
These styles are used by the numfmt_create() to define the type of the formatter.
NumberFormatter::PATTERN_DECIMAL
(integer)
NumberFormatter::DECIMAL
(integer)
NumberFormatter::CURRENCY
(integer)
NumberFormatter::PERCENT
(integer)
NumberFormatter::SCIENTIFIC
(integer)
NumberFormatter::SPELLOUT
(integer)
NumberFormatter::ORDINAL
(integer)
NumberFormatter::DURATION
(integer)
NumberFormatter::PATTERN_RULEBASED
(integer)
NumberFormatter::CURRENCY_ACCOUNTING
(integer)
($3.00) for negative currency amount
instead of -$3.00. Available as of PHP 7.4.1 and ICU 53.
NumberFormatter::DEFAULT_STYLE
(integer)
NumberFormatter::IGNORE
(integer)
These constants define how the numbers are parsed or formatted. They should be used as arguments to numfmt_format() and numfmt_parse().
NumberFormatter::TYPE_DEFAULT
(integer)
NumberFormatter::TYPE_INT32
(integer)
NumberFormatter::TYPE_INT64
(integer)
NumberFormatter::TYPE_DOUBLE
(integer)
NumberFormatter::TYPE_CURRENCY
(integer)
Number format attribute used by numfmt_get_attribute() and numfmt_set_attribute().
NumberFormatter::PARSE_INT_ONLY
(integer)
NumberFormatter::GROUPING_USED
(integer)
NumberFormatter::DECIMAL_ALWAYS_SHOWN
(integer)
NumberFormatter::MAX_INTEGER_DIGITS
(integer)
NumberFormatter::MIN_INTEGER_DIGITS
(integer)
NumberFormatter::INTEGER_DIGITS
(integer)
NumberFormatter::MAX_FRACTION_DIGITS
(integer)
NumberFormatter::MIN_FRACTION_DIGITS
(integer)
NumberFormatter::FRACTION_DIGITS
(integer)
NumberFormatter::MULTIPLIER
(integer)
NumberFormatter::GROUPING_SIZE
(integer)
NumberFormatter::ROUNDING_MODE
(integer)
NumberFormatter::ROUNDING_INCREMENT
(integer)
NumberFormatter::FORMAT_WIDTH
(integer)
NumberFormatter::PADDING_POSITION
(integer)
NumberFormatter::SECONDARY_GROUPING_SIZE
(integer)
NumberFormatter::SIGNIFICANT_DIGITS_USED
(integer)
NumberFormatter::MIN_SIGNIFICANT_DIGITS
(integer)
NumberFormatter::MAX_SIGNIFICANT_DIGITS
(integer)
NumberFormatter::LENIENT_PARSE
(integer)
Number format text attribute used by numfmt_get_text_attribute() and numfmt_set_text_attribute().
NumberFormatter::POSITIVE_PREFIX
(integer)
NumberFormatter::POSITIVE_SUFFIX
(integer)
NumberFormatter::NEGATIVE_PREFIX
(integer)
NumberFormatter::NEGATIVE_SUFFIX
(integer)
NumberFormatter::PADDING_CHARACTER
(integer)
NumberFormatter::CURRENCY_CODE
(integer)
NumberFormatter::DEFAULT_RULESET
(integer)
NumberFormatter::PUBLIC_RULESETS
(integer)
Number format symbols used by numfmt_get_symbol() and numfmt_set_symbol().
NumberFormatter::DECIMAL_SEPARATOR_SYMBOL
(integer)
NumberFormatter::GROUPING_SEPARATOR_SYMBOL
(integer)
NumberFormatter::PATTERN_SEPARATOR_SYMBOL
(integer)
NumberFormatter::PERCENT_SYMBOL
(integer)
NumberFormatter::ZERO_DIGIT_SYMBOL
(integer)
NumberFormatter::DIGIT_SYMBOL
(integer)
NumberFormatter::MINUS_SIGN_SYMBOL
(integer)
NumberFormatter::PLUS_SIGN_SYMBOL
(integer)
NumberFormatter::CURRENCY_SYMBOL
(integer)
NumberFormatter::INTL_CURRENCY_SYMBOL
(integer)
NumberFormatter::MONETARY_SEPARATOR_SYMBOL
(integer)
NumberFormatter::EXPONENTIAL_SYMBOL
(integer)
NumberFormatter::PERMILL_SYMBOL
(integer)
NumberFormatter::PAD_ESCAPE_SYMBOL
(integer)
NumberFormatter::INFINITY_SYMBOL
(integer)
NumberFormatter::NAN_SYMBOL
(integer)
NumberFormatter::SIGNIFICANT_DIGIT_SYMBOL
(integer)
NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL
(integer)
Rounding mode values used by numfmt_get_attribute()
and numfmt_set_attribute() with
NumberFormatter::ROUNDING_MODE attribute.
NumberFormatter::ROUND_CEILING
(integer)
NumberFormatter::ROUND_DOWN
(integer)
NumberFormatter::ROUND_FLOOR
(integer)
NumberFormatter::ROUND_HALFDOWN
(integer)
NumberFormatter::ROUND_HALFEVEN
(integer)
NumberFormatter::ROUND_HALFUP
(integer)
NumberFormatter::ROUND_UP
(integer)
Pad position values used by numfmt_get_attribute()
and numfmt_set_attribute() with
NumberFormatter::PADDING_POSITION attribute.
NumberFormatter::PAD_AFTER_PREFIX
(integer)
NumberFormatter::PAD_AFTER_SUFFIX
(integer)
NumberFormatter::PAD_BEFORE_PREFIX
(integer)
NumberFormatter::PAD_BEFORE_SUFFIX
(integer)
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
NumberFormatter::create -- numfmt_create -- NumberFormatter::__construct — Create a number formatter
Object oriented style (method)
$locale
, int $style
[, string $pattern
] ) : NumberFormatterProcedural style
Object oriented style (constructor):
$locale
, int $style
[, string $pattern
] )Creates a number formatter.
localeLocale in which the number would be formatted (locale name, e.g. en_CA).
style
Style of the formatting, one of the
format style constants. If
NumberFormatter::PATTERN_DECIMAL
or NumberFormatter::PATTERN_RULEBASED
is passed then the number format is opened using the given pattern,
which must conform to the syntax described in
» ICU DecimalFormat
documentation or
» ICU RuleBasedNumberFormat
documentation, respectively.
patternPattern string if the chosen style requires a pattern.
Returns NumberFormatter object or FALSE on error.
Example #1 numfmt_create() example
<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
$fmt = numfmt_create( 'it', NumberFormatter::SPELLOUT );
echo numfmt_format($fmt, 1142)."\n";
?>
Example #2 NumberFormatter::create() example
<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
echo $fmt->format(1234567.891234567890000)."\n";
$fmt = new NumberFormatter( 'it', NumberFormatter::SPELLOUT );
echo $fmt->format(1142)."\n";
?>
The above example will output:
1.234.567,891 millicentoquarantadue
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
NumberFormatter::formatCurrency -- numfmt_format_currency — Format a currency value
Object oriented style
$value
, string $currency
) : stringProcedural style
Format the currency value according to the formatter rules.
fmtNumberFormatter object.
valueThe numeric currency value.
currencyThe 3-letter ISO 4217 currency code indicating the currency to use.
String representing the formatted currency value, or FALSE on failure.
Example #1 numfmt_format_currency() example
<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::CURRENCY );
echo numfmt_format_currency($fmt, 1234567.891234567890000, "EUR")."\n";
echo numfmt_format_currency($fmt, 1234567.891234567890000, "RUR")."\n";
$fmt = numfmt_create( 'ru_RU', NumberFormatter::CURRENCY );
echo numfmt_format_currency($fmt, 1234567.891234567890000, "EUR")."\n";
echo numfmt_format_currency($fmt, 1234567.891234567890000, "RUR")."\n";
?>
Example #2 OO example
<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::CURRENCY );
echo $fmt->formatCurrency(1234567.891234567890000, "EUR")."\n";
echo $fmt->formatCurrency(1234567.891234567890000, "RUR")."\n";
$fmt = new NumberFormatter( 'ru_RU', NumberFormatter::CURRENCY );
echo $fmt->formatCurrency(1234567.891234567890000, "EUR")."\n";
echo $fmt->formatCurrency(1234567.891234567890000, "RUR")."\n";
?>
The above example will output:
1.234.567,89 € 1.234.567,89 RUR 1 234 567,89€ 1 234 567,89р.
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
NumberFormatter::format -- numfmt_format — Format a number
Object oriented style
Procedural style
Format a numeric value according to the formatter rules.
fmtNumberFormatter object.
valueThe value to format. Can be integer or float, other values will be converted to a numeric value.
typeThe formatting type to use.
Returns the string containing formatted value, or FALSE on error.
Example #1 numfmt_format() example
<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
$data = numfmt_format($fmt, 1234567.891234567890000);
if(intl_is_failure(numfmt_format($fmt))) {
report_error("Formatter error");
}
?>
Example #2 OO example
<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
$fmt->format(1234567.891234567890000);
if(intl_is_failure($fmt->getErrorCode())) {
report_error("Formatter error");
}
?>
The above example will output:
1.234.567,891
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
NumberFormatter::getAttribute -- numfmt_get_attribute — Get an attribute
Object oriented style
$attr
) : intProcedural style
Get a numeric attribute associated with the formatter. An example of a numeric attribute is the number of integer digits the formatter will produce.
fmtNumberFormatter object.
attrAttribute specifier - one of the numeric attribute constants.
Return attribute value on success, or FALSE on error.
Example #1 numfmt_get_attribute() example
<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
echo "Digits: ".numfmt_get_attribute($fmt, NumberFormatter::MAX_FRACTION_DIGITS)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
numfmt_set_attribute($fmt, NumberFormatter::MAX_FRACTION_DIGITS, 2);
echo "Digits: ".numfmt_get_attribute($fmt, NumberFormatter::MAX_FRACTION_DIGITS)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
?>
Example #2 OO example
<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
echo "Digits: ".$fmt->getAttribute(NumberFormatter::MAX_FRACTION_DIGITS)."\n";
echo $fmt->format(1234567.891234567890000)."\n";
$fmt->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, 2);
echo "Digits: ".$fmt->getAttribute(NumberFormatter::MAX_FRACTION_DIGITS)."\n";
echo $fmt->format(1234567.891234567890000)."\n";
?>
The above example will output:
Digits: 3 1.234.567,891 Digits: 2 1.234.567,89
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
NumberFormatter::getErrorCode -- numfmt_get_error_code — Get formatter's last error code
Object oriented style
Procedural style
Get error code from the last function performed by the formatter.
Returns error code from last formatter call.
Example #1 numfmt_get_error_code() example
<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
$data = numfmt_format($fmt, 1234567.891234567890000);
if(intl_is_failure(numfmt_get_error_code($fmt))) {
report_error("Formatter error");
}
?>
Example #2 OO example
<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
$fmt->format(1234567.891234567890000);
if(intl_is_failure($fmt->getErrorCode())) {
report_error("Formatter error");
}
?>
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
NumberFormatter::getErrorMessage -- numfmt_get_error_message — Get formatter's last error message
Object oriented style
Procedural style
Get error message from the last function performed by the formatter.
Returns error message from last formatter call.
Example #1 numfmt_get_error_message() example
<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
$data = numfmt_format($fmt, 1234567.891234567890000);
var_dump(numfmt_get_error_message($fmt));
?>
Example #2 OO example
<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
$fmt->format(1234567.891234567890000);
var_dump(numfmt_get_error_message($fmt));
?>
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
NumberFormatter::getLocale -- numfmt_get_locale — Get formatter locale
Object oriented style
$type
] ) : stringProcedural style
Get formatter locale name.
fmtNumberFormatter object.
type
You can choose between valid and actual locale (
Locale::VALID_LOCALE,
Locale::ACTUAL_LOCALE,
respectively). The default is the actual locale.
The locale name used to create the formatter.
Example #1 numfmt_get_locale() example
<?php
$req = 'fr_FR_PARIS';
$fmt = numfmt_create( $req, NumberFormatter::DECIMAL);
$res_val = numfmt_get_locale( $fmt, Locale::VALID_LOCALE );
$res_act = numfmt_get_locale( $fmt, Locale::ACTUAL_LOCALE );
printf( "Requested locale name: %s\nValid locale name: %s\nActual locale name: %s\n",
$req, $res_val, $res_act );
?>
The above example will output:
Requested locale name: fr_FR_PARIS Valid locale name: fr_FR Actual locale name: fr
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
NumberFormatter::getPattern -- numfmt_get_pattern — Get formatter pattern
Object oriented style
Procedural style
Extract pattern used by the formatter.
Pattern string that is used by the formatter, or FALSE if an error happens.
Example #1 numfmt_get_pattern() example
<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
echo "Pattern: ".numfmt_get_pattern($fmt)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
numfmt_set_pattern($fmt, "#0.# kg");
echo "Pattern: ".numfmt_get_pattern($fmt)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
?>
Example #2 OO example
<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
echo "Pattern: ".$fmt->getPattern()."\n";
echo $fmt->format(1234567.891234567890000)."\n";
$fmt->setPattern("#0.# kg");
echo "Pattern: ".$fmt->getPattern()."\n";
echo $fmt->format(1234567.891234567890000)."\n";
?>
The above example will output:
Pattern: #,##0.### 1.234.567,891 Pattern: #0.# kg 1234567,9 kg
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
NumberFormatter::getSymbol -- numfmt_get_symbol — Get a symbol value
Object oriented style
$attr
) : stringProcedural style
Get a symbol associated with the formatter. The formatter uses symbols to represent the special locale-dependent characters in a number, for example the percent sign. This API is not supported for rule-based formatters.
The symbol string or FALSE on error.
Example #1 numfmt_get_symbol() example
<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
echo "Sep: ".numfmt_get_symbol($fmt, NumberFormatter::GROUPING_SEPARATOR_SYMBOL)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
numfmt_set_symbol($fmt, NumberFormatter::GROUPING_SEPARATOR_SYMBOL, "*");
echo "Sep: ".numfmt_get_symbol($fmt, NumberFormatter::GROUPING_SEPARATOR_SYMBOL)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
?>
Example #2 OO example
<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
echo "Sep: ".$fmt->getSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL)."\n";
echo $fmt->format(1234567.891234567890000)."\n";
$fmt->setSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL, "*");
echo "Sep: ".$fmt->getSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL)."\n";
echo $fmt->format(1234567.891234567890000)."\n";
?>
The above example will output:
Sep: . 1.234.567,891 Sep: * 1*234*567,891
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
NumberFormatter::getTextAttribute -- numfmt_get_text_attribute — Get a text attribute
Object oriented style
$attr
) : stringProcedural style
Get a text attribute associated with the formatter. An example of a text
attribute is the suffix for positive numbers. If the formatter does not
understand the attribute,
U_UNSUPPORTED_ERROR
error is produced. Rule-based formatters only understand
NumberFormatter::DEFAULT_RULESET and
NumberFormatter::PUBLIC_RULESETS.
fmtNumberFormatter object.
attrAttribute specifier - one of the text attribute constants.
Return attribute value on success, or FALSE on error.
Example #1 numfmt_get_text_attribute() example
<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
echo "Prefix: ".numfmt_get_text_attribute($fmt, NumberFormatter::NEGATIVE_PREFIX)."\n";
echo numfmt_format($fmt, -1234567.891234567890000)."\n";
numfmt_set_text_attribute($fmt, NumberFormatter::NEGATIVE_PREFIX, "MINUS");
echo "Prefix: ".numfmt_get_text_attribute($fmt, NumberFormatter::NEGATIVE_PREFIX)."\n";
echo numfmt_format($fmt, -1234567.891234567890000)."\n";
?>
Example #2 OO example
<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
echo "Prefix: ".$fmt->getTextAttribute(NumberFormatter::NEGATIVE_PREFIX)."\n";
echo $fmt->format(-1234567.891234567890000)."\n";
$fmt->setTextAttribute(NumberFormatter::NEGATIVE_PREFIX, "MINUS");
echo "Prefix: ".$fmt->getTextAttribute(NumberFormatter::NEGATIVE_PREFIX)."\n";
echo $fmt->format(-1234567.891234567890000)."\n";
?>
The above example will output:
Prefix: - -1.234.567,891 Prefix: MINUS MINUS1.234.567,891
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
NumberFormatter::parseCurrency -- numfmt_parse_currency — Parse a currency number
Object oriented style
$value
, string &$currency
[, int &$position
] ) : floatProcedural style
$fmt
, string $value
, string &$currency
[, int &$position
] ) : floatParse a string into a double and a currency using the current formatter.
fmtNumberFormatter object.
currencyParameter to receive the currency name (3-letter ISO 4217 currency code).
positionOffset in the string at which to begin parsing. On return, this value will hold the offset at which parsing ended.
The parsed numeric value or FALSE on error.
Example #1 numfmt_parse_currency() example
<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::CURRENCY );
$num = "1.234.567,89\xc2\xa0$";
echo "We have ".numfmt_parse_currency($fmt, $num, $curr)." in $curr\n";
?>
Example #2 OO example
<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::CURRENCY );
$num = "1.234.567,89\xc2\xa0$";
echo "We have ".$fmt->parseCurrency($num, $curr)." in $curr\n";
?>
The above example will output:
We have 1234567.89 in USD
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
NumberFormatter::parse -- numfmt_parse — Parse a number
Object oriented style
Procedural style
Parse a string into a number using the current formatter rules.
fmtNumberFormatter object.
type
The
formatting type to use. By default,
NumberFormatter::TYPE_DOUBLE is used.
positionOffset in the string at which to begin parsing. On return, this value will hold the offset at which parsing ended.
The value of the parsed number or FALSE on error.
Example #1 numfmt_parse() example
<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
$num = "1.234.567,891";
echo numfmt_parse($fmt, $num)."\n";
echo numfmt_parse($fmt, $num, NumberFormatter::TYPE_INT32)."\n";
?>
Example #2 OO example
<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
$num = "1.234.567,891";
echo $fmt->parse($num)."\n";
echo $fmt->parse($num, NumberFormatter::TYPE_INT32)."\n";
?>
The above example will output:
1234567.891 1234567
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
NumberFormatter::setAttribute -- numfmt_set_attribute — Set an attribute
Object oriented style
$attr
, int $value
) : boolProcedural style
Set a numeric attribute associated with the formatter. An example of a numeric attribute is the number of integer digits the formatter will produce.
fmtNumberFormatter object.
attrAttribute specifier - one of the numeric attribute constants.
valueThe attribute value.
Returns TRUE on success or FALSE on failure.
Example #1 numfmt_set_attribute() example
<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
echo "Digits: ".numfmt_get_attribute($fmt, NumberFormatter::MAX_FRACTION_DIGITS)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
numfmt_set_attribute($fmt, NumberFormatter::MAX_FRACTION_DIGITS, 2);
echo "Digits: ".numfmt_get_attribute($fmt, NumberFormatter::MAX_FRACTION_DIGITS)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
?>
Example #2 OO example
<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
echo "Digits: ".$fmt->getAttribute(NumberFormatter::MAX_FRACTION_DIGITS)."\n";
echo $fmt->format(1234567.891234567890000)."\n";
$fmt->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, 2);
echo "Digits: ".$fmt->getAttribute(NumberFormatter::MAX_FRACTION_DIGITS)."\n";
echo $fmt->format(1234567.891234567890000)."\n";
?>
The above example will output:
Digits: 3 1.234.567,891 Digits: 2 1.234.567,89
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
NumberFormatter::setPattern -- numfmt_set_pattern — Set formatter pattern
Object oriented style
$pattern
) : boolProcedural style
Set the pattern used by the formatter. Can not be used on a rule-based formatter.
fmtNumberFormatter object.
patternPattern in syntax described in » ICU DecimalFormat documentation.
Returns TRUE on success or FALSE on failure.
Example #1 numfmt_set_pattern() example
<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
echo "Pattern: ".numfmt_get_pattern($fmt)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
numfmt_set_pattern($fmt, "#0.# kg");
echo "Pattern: ".numfmt_get_pattern($fmt)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
?>
Example #2 OO example
<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
echo "Pattern: ".$fmt->getPattern()."\n";
echo $fmt->format(1234567.891234567890000)."\n";
$fmt->setPattern("#0.# kg");
echo "Pattern: ".$fmt->getPattern()."\n";
echo $fmt->format(1234567.891234567890000)."\n";
?>
The above example will output:
Pattern: #,##0.### 1.234.567,891 Pattern: #0.# kg 1234567,9 kg
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
NumberFormatter::setSymbol -- numfmt_set_symbol — Set a symbol value
Object oriented style
$attr
, string $value
) : boolProcedural style
Set a symbol associated with the formatter. The formatter uses symbols to represent the special locale-dependent characters in a number, for example the percent sign. This API is not supported for rule-based formatters.
fmtNumberFormatter object.
attrSymbol specifier, one of the format symbol constants.
valueText for the symbol.
Returns TRUE on success or FALSE on failure.
Example #1 numfmt_set_symbol() example
<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
echo "Sep: ".numfmt_get_symbol($fmt, NumberFormatter::GROUPING_SEPARATOR_SYMBOL)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
numfmt_set_symbol($fmt, NumberFormatter::GROUPING_SEPARATOR_SYMBOL, "*");
echo "Sep: ".numfmt_get_symbol($fmt, NumberFormatter::GROUPING_SEPARATOR_SYMBOL)."\n";
echo numfmt_format($fmt, 1234567.891234567890000)."\n";
?>
Example #2 OO example
<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
echo "Sep: ".$fmt->getSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL)."\n";
echo $fmt->format(1234567.891234567890000)."\n";
$fmt->setSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL, "*");
echo "Sep: ".$fmt->getSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL)."\n";
echo $fmt->format(1234567.891234567890000)."\n";
?>
The above example will output:
Sep: . 1.234.567,891 Sep: * 1*234*567,891
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
NumberFormatter::setTextAttribute -- numfmt_set_text_attribute — Set a text attribute
Object oriented style
$attr
, string $value
) : boolProcedural style
Set a text attribute associated with the formatter. An example of a text
attribute is the suffix for positive numbers. If the formatter does not
understand the attribute,
U_UNSUPPORTED_ERROR
error is produced. Rule-based formatters only understand
NumberFormatter::DEFAULT_RULESET and
NumberFormatter::PUBLIC_RULESETS.
fmtNumberFormatter object.
attrAttribute specifier - one of the text attribute constants.
valueText for the attribute value.
Returns TRUE on success or FALSE on failure.
Example #1 numfmt_set_text_attribute() example
<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
echo "Prefix: ".numfmt_get_text_attribute($fmt, NumberFormatter::NEGATIVE_PREFIX)."\n";
echo numfmt_format($fmt, -1234567.891234567890000)."\n";
numfmt_set_text_attribute($fmt, NumberFormatter::NEGATIVE_PREFIX, "MINUS");
echo "Prefix: ".numfmt_get_text_attribute($fmt, NumberFormatter::NEGATIVE_PREFIX)."\n";
echo numfmt_format($fmt, -1234567.891234567890000)."\n";
?>
Example #2 OO example
<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
echo "Prefix: ".$fmt->getTextAttribute(NumberFormatter::NEGATIVE_PREFIX)."\n";
echo $fmt->format(-1234567.891234567890000)."\n";
$fmt->setTextAttribute(NumberFormatter::NEGATIVE_PREFIX, "MINUS");
echo "Prefix: ".$fmt->getTextAttribute(NumberFormatter::NEGATIVE_PREFIX)."\n";
echo $fmt->format(-1234567.891234567890000)."\n";
?>
The above example will output:
Prefix: - -1.234.567,891 Prefix: MINUS MINUS1.234.567,891
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
A "Locale" is an identifier used to get language, culture, or regionally-specific behavior from an API. PHP locales are organized and identified the same way that the CLDR locales used by ICU (and many vendors of Unix-like operating systems, the Mac, Java, and so forth) use. Locales are identified using RFC 4646 language tags (which use hyphen, not underscore) in addition to the more traditional underscore-using identifiers. Unless otherwise noted the functions in this class are tolerant of both formats.
Examples of identifiers include:
The Locale class (and related procedural functions) are used to interact with locale identifiers--to verify that an ID is well-formed, valid, etc. The extensions used by CLDR in UAX #35 (and inherited by ICU) are valid and used wherever they would be in ICU normally.
Locales cannot be instantiated as objects. All of the functions/methods provided are static.
The null or empty string obtains the "root" locale. The "root" locale is equivalent to "en_US_POSIX" in CLDR. Language tags (and thus locale identifiers) are case insensitive. There exists a canonicalization function to make case match the specification.
$langtag
, string $locale
[, bool $canonicalize = FALSE
] ) : bool$langtag
, string $locale
[, bool $canonicalize = FALSE
[, string $default
]] ) : string
Locale::DEFAULT_LOCALE
(null)
These constants describe the choice of the locale for the getLocale method of different classes.
Locale::ACTUAL_LOCALE
(string)
Locale::VALID_LOCALE
(string)
These constants define how the Locales are parsed or composed. They should be used as keys in the argument array to locale_compose() and are returned from locale_parse() as keys of the returned associative array.
Locale::LANG_TAG
(string)
Locale::EXTLANG_TAG
(string)
Locale::SCRIPT_TAG
(string)
Locale::REGION_TAG
(string)
Locale::VARIANT_TAG
(string)
Locale::GRANDFATHERED_LANG_TAG
(string)
Locale::PRIVATE_TAG
(string)
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Locale::acceptFromHttp -- locale_accept_from_http — Tries to find out best available locale based on HTTP "Accept-Language" header
Object oriented style
$header
) : stringProcedural style
$header
) : stringTries to find locale that can satisfy the language list that is requested by the HTTP "Accept-Language" header.
headerThe string containing the "Accept-Language" header according to format in RFC 2616.
The corresponding locale identifier.
Example #1 locale_accept_from_http() example
<?php
$locale = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']);
echo $locale;
?>
Example #2 OO example
<?php
$locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
echo $locale;
?>
The above example will output:
en_US
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Locale::canonicalize -- locale_canonicalize — Canonicalize the locale string
$locale
) : string
This function is currently not documented; only its argument list is available.
locale
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Locale::composeLocale -- locale_compose — Returns a correctly ordered and delimited locale ID
Object oriented style
$subtags
) : stringProcedural style
$subtags
) : stringReturns a correctly ordered and delimited locale ID the keys identify the particular locale ID subtags, and the values are the associated subtag values.
subtagsan array containing a list of key-value pairs, where the keys identify the particular locale ID subtags, and the values are the associated subtag values.
Note:
The 'variant' and 'private' subtags can take maximum 15 values whereas 'extlang' can take maximum 3 values.e.g. Variants are allowed with the suffix ranging from 0-14. Hence the keys for the input array can be variant0, variant1, ...,variant14. In the returned locale id, the subtag is ordered by suffix resulting in variant0 followed by variant1 followed by variant2 and so on.
The 'variant', 'private' and 'extlang' multiple values can be specified both as array under specific key (e.g. 'variant') and as multiple numbered keys (e.g. 'variant0', 'variant1', etc.).
The corresponding locale identifier.
Example #1 locale_compose() example
<?php
$arr = array(
'language'=>'en' ,
'script' =>'Hans' ,
'region' =>'CN',
'variant2'=>'rozaj' ,
'variant1'=>'nedis' ,
'private1'=>'prv1' ,
'private2'=>'prv2'
);
echo locale_compose( $arr );
?>
Example #2 OO example
<?php
$arr = array(
'language'=>'en' ,
'script' =>'Hans' ,
'region' =>'CN',
'variant2'=>'rozaj' ,
'variant1'=>'nedis' ,
'private1'=>'prv1' ,
'private2'=>'prv2'
);
echo Locale::composeLocale( $arr );
?>
The above example will output:
Locale: en_Hans_CN_nedis_rozaj_x_prv1_prv2
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Locale::filterMatches -- locale_filter_matches — Checks if a language tag filter matches with locale
Object oriented style
$langtag
, string $locale
[, bool $canonicalize = FALSE
] ) : boolProcedural style
$langtag
, string $locale
[, bool $canonicalize = FALSE
] ) : boolChecks if a $langtag filter matches with $locale according to RFC 4647's basic filtering algorithm
langtagThe language tag to check
localeThe language range to check against
canonicalizeIf true, the arguments will be converted to canonical form before matching.
TRUE if $locale matches $langtag FALSE otherwise.
Example #1 locale_filter_matches() example
<?php
echo (locale_filter_matches('de-DEVA','de-DE', false)) ? "Matches" : "Does not match";
echo '; ';
echo (locale_filter_matches('de-DE_1996','de-DE', false)) ? "Matches" : "Does not match";
?>
Example #2 OO example
<?php
echo (Locale::filterMatches('de-DEVA','de-DE', false)) ? "Matches" : "Does not match";
echo '; ';
echo (Locale::filterMatches('de-DE-1996','de-DE', false)) ? "Matches" : "Does not match";
?>
The above example will output:
Does not match; Matches
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Locale::getAllVariants -- locale_get_all_variants — Gets the variants for the input locale
Object oriented style
$locale
) : arrayProcedural style
$locale
) : arrayGets the variants for the input locale
localeThe locale to extract the variants from
The array containing the list of all variants subtag for the locale
or NULL if not present
Example #1 locale_get_all_variants() example
<?php
$arr = locale_get_all_variants('sl_IT_NEDIS_ROJAZ_1901');
var_export( $arr );
?>
Example #2 OO example
<?php
$arr = Locale::getAllVariants('sl_IT_NEDIS_ROJAZ_1901');
var_export( $arr );
?>
The above example will output:
array (
0 => 'NEDIS',
1 => 'ROJAZ',
2 => '1901',
)
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Locale::getDefault -- locale_get_default — Gets the default locale value from the INTL global 'default_locale'
Object oriented style
Procedural style
Gets the default locale value. At the PHP initialization this value is set to 'intl.default_locale' value from php.ini if that value exists or from ICU's function uloc_getDefault().
The current runtime locale
Example #1 locale_get_default() example
<?php
ini_set('intl.default_locale', 'de-DE');
echo locale_get_default();
echo '; ';
locale_set_default('fr');
echo locale_get_default();
?>
Example #2 OO example
<?php
ini_set('intl.default_locale', 'de-DE');
echo Locale::getDefault();
echo '; ';
Locale::setDefault('fr');
echo Locale::getDefault();
?>
The above example will output:
de-DE; fr
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Locale::getDisplayLanguage -- locale_get_display_language — Returns an appropriately localized display name for language of the inputlocale
Object oriented style
$locale
[, string $in_locale
] ) : stringProcedural style
$locale
[, string $in_locale
] ) : string
Returns an appropriately localized display name for language of the input
locale. If is NULL then the default locale is used.
localeThe locale to return a display language for
in_localeOptional format locale to use to display the language name
display name of the language for the $locale in the format appropriate for $in_locale.
Example #1 locale_get_display_language() example
<?php
echo locale_get_display_language('sl-Latn-IT-nedis', 'en');
echo ";\n";
echo locale_get_display_language('sl-Latn-IT-nedis', 'fr');
echo ";\n";
echo locale_get_display_language('sl-Latn-IT-nedis', 'de');
?>
Example #2 OO example
<?php
echo Locale::getDisplayLanguage('sl-Latn-IT-nedis', 'en');
echo ";\n";
echo Locale::getDisplayLanguage('sl-Latn-IT-nedis', 'fr');
echo ";\n";
echo Locale::getDisplayLanguage('sl-Latn-IT-nedis', 'de');
?>
The above example will output:
Slovenian; slov\xc3\xa8ne; Slowenisch
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Locale::getDisplayName -- locale_get_display_name — Returns an appropriately localized display name for the input locale
Object oriented style
$locale
[, string $in_locale
] ) : stringProcedural style
$locale
[, string $in_locale
] ) : string
Returns an appropriately localized display name for the input locale. If $locale is
NULL then the default locale is used.
localeThe locale to return a display name for.
in_localeoptional format locale
Display name of the locale in the format appropriate for $in_locale.
Example #1 locale_get_display_name() example
<?php
echo locale_get_display_name('sl-Latn-IT-nedis', 'en');
echo ";\n";
echo locale_get_display_name('sl-Latn-IT-nedis', 'fr');
echo ";\n";
echo locale_get_display_name('sl-Latn-IT-nedis', 'de');
?>
Example #2 OO example
<?php
echo Locale::getDisplayName('sl-Latn-IT-nedis', 'en');
echo ";\n";
echo Locale::getDisplayName('sl-Latn-IT-nedis', 'fr');
echo ";\n";
echo Locale::getDisplayName('sl-Latn-IT-nedis', 'de');
?>
The above example will output:
Slovenian (Latin, Italy, Natisone dialect);
slov\xc3\xa8ne (latin, Italie, dialecte de Natisone;
Slowenisch (Lateinisch, Italien, NEDIS)
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Locale::getDisplayRegion -- locale_get_display_region — Returns an appropriately localized display name for region of the input locale
Object oriented style
$locale
[, string $in_locale
] ) : stringProcedural style
$locale
[, string $in_locale
] ) : string
Returns an appropriately localized display name for region of the input
locale. If is NULL then the default locale is used.
localeThe locale to return a display region for.
in_localeOptional format locale to use to display the region name
display name of the region for the $locale in the format appropriate for $in_locale.
Example #1 locale_get_display_region() example
<?php
echo locale_get_display_region('sl-Latn-IT-nedis', 'en');
echo ";\n";
echo locale_get_display_region('sl-Latn-IT-nedis', 'fr');
echo ";\n";
echo locale_get_display_region('sl-Latn-IT-nedis', 'de');
?>
Example #2 OO example
<?php
echo Locale::getDisplayRegion('sl-Latn-IT-nedis', 'en');
echo ";\n";
echo Locale::getDisplayRegion('sl-Latn-IT-nedis', 'fr');
echo ";\n";
echo Locale::getDisplayRegion('sl-Latn-IT-nedis', 'de');
?>
The above example will output:
Italy; Italie; Italien
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Locale::getDisplayScript -- locale_get_display_script — Returns an appropriately localized display name for script of the input locale
Object oriented style
$locale
[, string $in_locale
] ) : stringProcedural style
$locale
[, string $in_locale
] ) : string
Returns an appropriately localized display name for script of the input
locale. If is NULL then the default locale is used.
localeThe locale to return a display script for
in_localeOptional format locale to use to display the script name
Display name of the script for the $locale in the format appropriate for $in_locale.
Example #1 locale_get_display_script() example
<?php
echo locale_get_display_script('sl-Latn-IT-nedis', 'en');
echo ";\n";
echo locale_get_display_script('sl-Latn-IT-nedis', 'fr');
echo ";\n";
echo locale_get_display_script('sl-Latn-IT-nedis', 'de');
?>
Example #2 OO example
<?php
echo Locale::getDisplayScript('sl-Latn-IT-nedis', 'en');
echo ";\n";
echo Locale::getDisplayScript('sl-Latn-IT-nedis', 'fr');
echo ";\n";
echo Locale::getDisplayScript('sl-Latn-IT-nedis', 'de');
?>
The above example will output:
Latin; latin; Lateinisch
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Locale::getDisplayVariant -- locale_get_display_variant — Returns an appropriately localized display name for variants of the input locale
Object oriented style
$locale
[, string $in_locale
] ) : stringProcedural style
$locale
[, string $in_locale
] ) : string
Returns an appropriately localized display name for variants of the input
locale. If is NULL then the default locale is used.
localeThe locale to return a display variant for
in_localeOptional format locale to use to display the variant name
Display name of the variant for the $locale in the format appropriate for $in_locale.
Example #1 locale_get_display_variant() example
<?php
echo locale_get_display_variant('sl-Latn-IT-nedis', 'en');
echo ";\n";
echo locale_get_display_variant('sl-Latn-IT-nedis', 'fr');
echo ";\n";
echo locale_get_display_variant('sl-Latn-IT-nedis', 'de');
?>
Example #2 OO example
<?php
echo Locale::getDisplayVariant('sl-Latn-IT-nedis', 'en');
echo ";\n";
echo Locale::getDisplayVariant('sl-Latn-IT-nedis', 'fr');
echo ";\n";
echo Locale::getDisplayVariant('sl-Latn-IT-nedis', 'de');
?>
The above example will output:
Natisone dialect;
dialecte de Natisone;
NEDIS
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Locale::getKeywords -- locale_get_keywords — Gets the keywords for the input locale
Object oriented style
$locale
) : arrayProcedural style
$locale
) : arrayGets the keywords for the input locale.
localeThe locale to extract the keywords from
Associative array containing the keyword-value pairs for this locale
Example #1 locale_get_keywords() example
<?php
$keywords_arr = locale_get_keywords('de_DE@currency=EUR;collation=PHONEBOOK');
if ($keywords_arr) {
foreach ($keywords_arr as $key => $value) {
echo "$key = $value\n";
}
}
?>
Example #2 OO example
<?php
$keywords_arr = Locale::getKeywords('de_DE@currency=EUR;collation=PHONEBOOK');
if ($keywords_arr) {
foreach ($keywords_arr as $key => $value) {
echo "$key = $value\n";
}
}
?>
The above example will output:
collation = PHONEBOOK currency = EUR
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Locale::getPrimaryLanguage -- locale_get_primary_language — Gets the primary language for the input locale
Object oriented style
$locale
) : stringProcedural style
$locale
) : stringGets the primary language for the input locale
localeThe locale to extract the primary language code from
The language code associated with the language or NULL in case of error.
Example #1 locale_get_primary_language() example
<?php
echo locale_get_primary_language('zh-Hant');
?>
Example #2 OO example
<?php
echo Locale::getPrimaryLanguage('zh-Hant');
?>
The above example will output:
zh
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Locale::getRegion -- locale_get_region — Gets the region for the input locale
Object oriented style
$locale
) : stringProcedural style
$locale
) : stringGets the region for the input locale.
localeThe locale to extract the region code from
The region subtag for the locale or NULL if not present
Example #1 locale_get_region() example
<?php
echo locale_get_region('de-CH-1901');
?>
Example #2 OO example
<?php
echo Locale::getRegion('de-CH-1901');
?>
The above example will output:
CH
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Locale::getScript -- locale_get_script — Gets the script for the input locale
Object oriented style
$locale
) : stringProcedural style
$locale
) : stringGets the script for the input locale.
localeThe locale to extract the script code from
The script subtag for the locale or NULL if not present
Example #1 locale_get_script() example
<?php
echo locale_get_script('sr-Cyrl');
?>
Example #2 OO example
<?php
echo Locale::getScript('sr-Cyrl');
?>
The above example will output:
Cyrl
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Locale::lookup -- locale_lookup — Searches the language tag list for the best match to the language
Object oriented style
$langtag
, string $locale
[, bool $canonicalize = FALSE
[, string $default
]] ) : stringProcedural style
$langtag
, string $locale
[, bool $canonicalize = FALSE
[, string $default
]] ) : string
Searches the items in langtag for the best match to
the language range specified in locale according to
RFC 4647's lookup algorithm.
langtag
An array containing a list of language tags to compare to
locale. Maximum 100 items allowed.
localeThe locale to use as the language range when matching.
canonicalize
If true, the arguments will be converted to canonical form before matching.
defaultThe locale to use if no match is found.
The closest matching language tag or default value.
Example #1 locale_lookup() example
<?php
$arr = array(
'de-DEVA',
'de-DE-1996',
'de',
'de-De'
);
echo locale_lookup($arr, 'de-DE-1996-x-prv1-prv2', true, 'en_US');
?>
Example #2 OO example
<?php
$arr = array(
'de-DEVA',
'de-DE-1996',
'de',
'de-De'
);
echo Locale::lookup($arr, 'de-DE-1996-x-prv1-prv2', true, 'en_US');
?>
The above example will output:
de_de_1996
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Locale::parseLocale -- locale_parse — Returns a key-value array of locale ID subtag elements
Object oriented style
$locale
) : arrayProcedural style
$locale
) : arrayReturns a key-value array of locale ID subtag elements.
localeThe locale to extract the subtag array from. Note: The 'variant' and 'private' subtags can take maximum 15 values whereas 'extlang' can take maximum 3 values.
Returns an array containing a list of key-value pairs, where the keys identify the particular locale ID subtags, and the values are the associated subtag values. The array will be ordered as the locale id subtags e.g. in the locale id if variants are '-varX-varY-varZ' then the returned array will have variant0=>varX , variant1=>varY , variant2=>varZ
Returns NULL when the length of locale exceeds
INTL_MAX_LOCALE_LEN.
Example #1 locale_parse() example
<?php
$arr = locale_parse('sl-Latn-IT-nedis');
if ($arr) {
foreach ($arr as $key => $value) {
echo "$key : $value , ";
}
}
?>
Example #2 OO example
<?php
$arr = Locale::parseLocale('sl-Latn-IT-nedis');
if ($arr) {
foreach ($arr as $key => $value) {
echo "$key : $value , ";
}
}
?>
The above example will output:
language : sl , script : Latn , region : IT , variant0 : NEDIS ,
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Locale::setDefault -- locale_set_default — Sets the default runtime locale
Object oriented style
$locale
) : boolProcedural style
$locale
) : boolSets the default runtime locale to $locale. This changes the value of INTL global 'default_locale' locale identifier. UAX #35 extensions are accepted.
localeIs a BCP 47 compliant language tag.
Returns TRUE on success or FALSE on failure.
Example #1 locale_set_default() example
<?php
locale_set_default('de-DE');
echo locale_get_default();
?>
Example #2 OO example
<?php
Locale::setDefault('de-DE');
echo Locale::getDefault();
?>
The above example will output:
de-DE
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Normalization is a process that involves transforming characters and sequences of characters into a formally-defined underlying representation. This process is most important when text needs to be compared for sorting and searching, but it is also used when storing text to ensure that the text is stored in a consistent representation.
The Unicode Consortium has defined a number of normalization forms reflecting the various needs of applications:
The following constants define the normalization form used by the normalizer:
Normalizer::FORM_C
(integer)
Normalizer::FORM_D
(integer)
Normalizer::FORM_KC
(integer)
Normalizer::FORM_KD
(integer)
Normalizer::NONE
(integer)
Normalizer::OPTION_DEFAULT
(integer)
(PHP 7 >= 7.3)
Normalizer::getRawDecomposition -- normalizer_get_raw_decomposition — Gets the Decomposition_Mapping property for the given UTF-8 encoded code point
Object oriented style
$input
) : stringProcedural style
$input
) : stringGets the Decomposition_Mapping property, as specified in the Unicode Character Database (UCD), for the given UTF-8 encoded code point.
inputThe input string, which should be a single, UTF-8 encoded, code point.
Returns a string containing the Decomposition_Mapping property, if present in the UCD.
Returns NULL if there is no Decomposition_Mapping property for the character.
Example #1 Normalizer::getRawDecomposition() example
<?php
$result = "";
$strings = [
"a",
"\u{FFDA}",
"\u{FDFA}",
"",
"aa",
"\xF5",
];
foreach ($strings as $string) {
$decomposition = Normalizer::getRawDecomposition($string);
// $decomposition = normalizer_get_raw_decomposition($string); Procedural way
$error_code = intl_get_error_code();
$error_message = intl_get_error_message();
$string_hex = bin2hex($string);
$result .= "---------------------\n";
if ($decomposition === null) {
$result .= "'$string_hex' has no decomposition mapping\n" ;
} else {
$result .= "'$string_hex' has the decomposition mapping '" . bin2hex($decomposition) . "'\n" ;
}
$result .= "error info: '$error_message' ($error_code)\n";
}
echo $result;
?>
The above example will output:
--------------------- '61' has no decomposition mapping error info: 'U_ZERO_ERROR' (0) --------------------- 'efbf9a' has the decomposition mapping 'e385a1' error info: 'U_ZERO_ERROR' (0) --------------------- 'efb7ba' has the decomposition mapping 'd8b5d984d98920d8a7d984d984d98720d8b9d984d98ad98720d988d8b3d984d985' error info: 'U_ZERO_ERROR' (0) --------------------- '' has no decomposition mapping error info: 'Input string must be exactly one UTF-8 encoded code point long.: U_ILLEGAL_ARGUMENT_ERROR' (1) --------------------- '6161' has no decomposition mapping error info: 'Input string must be exactly one UTF-8 encoded code point long.: U_ILLEGAL_ARGUMENT_ERROR' (1) --------------------- 'f5' has no decomposition mapping error info: 'Code point out of range: U_ILLEGAL_ARGUMENT_ERROR' (1)
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Normalizer::isNormalized -- normalizer_is_normalized — Checks if the provided string is already in the specified normalization form
Object oriented style
$input
[, int $form = Normalizer::FORM_C
] ) : boolProcedural style
$input
[, int $form = Normalizer::FORM_C
] ) : boolChecks if the provided string is already in the specified normalization form.
inputThe input string to normalize
formOne of the normalization forms.
TRUE if normalized, FALSE otherwise or if there an error
Example #1 normalizer_is_normalized() example
<?php
$char_A_ring = "\xC3\x85"; // 'LATIN CAPITAL LETTER A WITH RING ABOVE' (U+00C5)
$char_combining_ring_above = "\xCC\x8A"; // 'COMBINING RING ABOVE' (U+030A)
$char_orig = 'A' . $char_combining_ring_above;
$char_norm = normalizer_normalize( 'A' . $char_combining_ring_above, Normalizer::FORM_C );
echo ( normalizer_is_normalized($char_orig, Normalizer::FORM_C) ) ? "normalized" : "not normalized";
echo '; ';
echo ( normalizer_is_normalized($char_norm, Normalizer::FORM_C) ) ? "normalized" : "not normalized";
?>
Example #2 OO example
<?php
$char_A_ring = "\xC3\x85"; // 'LATIN CAPITAL LETTER A WITH RING ABOVE' (U+00C5)
$char_combining_ring_above = "\xCC\x8A"; // 'COMBINING RING ABOVE' (U+030A)
$char_orig = 'A' . $char_combining_ring_above;
$char_norm = Normalizer::normalize( 'A' . $char_combining_ring_above, Normalizer::FORM_C );
echo ( Normalizer::isNormalized($char_orig, Normalizer::FORM_C) ) ? "normalized" : "not normalized";
echo '; ';
echo ( Normalizer::isNormalized($char_norm, Normalizer::FORM_C) ) ? "normalized" : "not normalized";
?>
The above example will output:
not normalized; normalized
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Normalizer::normalize -- normalizer_normalize — Normalizes the input provided and returns the normalized string
Object oriented style
$input
[, int $form = Normalizer::FORM_C
] ) : stringProcedural style
$input
[, int $form = Normalizer::FORM_C
] ) : stringNormalizes the input provided and returns the normalized string
inputThe input string to normalize
formOne of the normalization forms.
The normalized string or FALSE if an error occurred.
Example #1 normalizer_normalize() example
<?php
$char_A_ring = "\xC3\x85"; // 'LATIN CAPITAL LETTER A WITH RING ABOVE' (U+00C5)
$char_combining_ring_above = "\xCC\x8A"; // 'COMBINING RING ABOVE' (U+030A)
$char_1 = normalizer_normalize( $char_A_ring, Normalizer::FORM_C );
$char_2 = normalizer_normalize( 'A' . $char_combining_ring_above, Normalizer::FORM_C );
echo urlencode($char_1);
echo ' ';
echo urlencode($char_2);
?>
Example #2 OO example
<?php
$char_A_ring = "\xC3\x85"; // 'LATIN CAPITAL LETTER A WITH RING ABOVE' (U+00C5)
$char_combining_ring_above = "\xCC\x8A"; // 'COMBINING RING ABOVE' (U+030A)
$char_1 = Normalizer::normalize( $char_A_ring, Normalizer::FORM_C );
$char_2 = Normalizer::normalize( 'A' . $char_combining_ring_above, Normalizer::FORM_C );
echo urlencode($char_1);
echo ' ';
echo urlencode($char_2);
?>
The above example will output:
%C3%85 %C3%85
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
MessageFormatter is a concrete class that enables users to produce concatenated, language-neutral messages. The methods supplied in this class are used to build all the messages that are seen by end users.
The MessageFormatter class assembles messages from various fragments (such as text fragments, numbers, and dates) supplied by the program. Because of the MessageFormatter class, the program does not need to know the order of the fragments. The class uses the formatting specifications for the fragments to assemble them into a message that is contained in a single string within a resource bundle. For example, MessageFormatter enables you to print the phrase "Finished printing x out of y files..." in a manner that still allows for flexibility in translation.
Previously, an end user message was created as a sentence and handled as a string. This procedure created problems for localizers because the sentence structure, word order, number format and so on are very different from language to language. The language-neutral way to create messages keeps each part of the message separate and provides keys to the data. Using these keys, the MessageFormatter class can concatenate the parts of the message, localize them, and display a well-formed string to the end user.
MessageFormatter takes a set of objects, formats them, and then inserts the formatted strings into the pattern at the appropriate places. Choice formats can be used in conjunction with MessageFormatter to handle plurals, match numbers, and select from an array of items. Typically, the message format will come from resources and the arguments will be dynamically set at runtime.
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
MessageFormatter::create -- MessageFormatter::__construct -- msgfmt_create — Constructs a new Message Formatter
Object oriented style (method)
Object oriented style (constructor):
$locale
, string $pattern
)Procedural style
Constructs a new Message Formatter
localeThe locale to use when formatting arguments
patternThe pattern string to stick arguments into. The pattern uses an 'apostrophe-friendly' syntax; it is run through » umsg_autoQuoteApostrophe before being interpreted.
The formatter object
When invoked as constructor, on failure an IntlException is thrown.
Example #1 msgfmt_create() example
<?php
$fmt = msgfmt_create("en_US", "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree");
echo msgfmt_format($fmt, array(4560, 123, 4560/123));
$fmt = msgfmt_create("de", "{0,number,integer} Affen auf {1,number,integer} Bäumen sind {2,number} Affen pro Baum");
echo msgfmt_format($fmt, array(4560, 123, 4560/123));
?>
Example #2 OO example
<?php
$fmt = new MessageFormatter("en_US", "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree");
echo $fmt->format(array(4560, 123, 4560/123));
$fmt = new MessageFormatter("de", "{0,number,integer} Affen auf {1,number,integer} Bäumen sind {2,number} Affen pro Baum");
echo $fmt->format(array(4560, 123, 4560/123));
?>
The above example will output:
4,560 monkeys on 123 trees make 37.073 monkeys per tree 4.560 Affen auf 123 Bäumen sind 37,073 Affen pro Baum
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
MessageFormatter::formatMessage -- msgfmt_format_message — Quick format message
Object oriented style
$locale
, string $pattern
, array $args
) : stringProcedural style
$locale
, string $pattern
, array $args
) : stringQuick formatting function that formats the string without having to explicitly create the formatter object. Use this function when the format operation is done only once and does not need and parameters or state to be kept.
localeThe locale to use for formatting locale-dependent parts
patternThe pattern string to insert things into. The pattern uses an 'apostrophe-friendly' syntax; it is run through » umsg_autoQuoteApostrophe before being interpreted.
args
The formatted pattern string or FALSE if an error occurred
Example #1 msgfmt_format_message() example
<?php
echo msgfmt_format_message("en_US", "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree\n", array(4560, 123, 4560/123));
echo msgfmt_format_message("de", "{0,number,integer} Affen auf {1,number,integer} Bäumen sind {2,number} Affen pro Baum\n", array(4560, 123, 4560/123));
?>
Example #2 OO example
<?php
echo MessageFormatter::formatMessage("en_US", "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree\n", array(4560, 123, 4560/123));
echo MessageFormatter::formatMessage("de", "{0,number,integer} Affen auf {1,number,integer} Bäumen sind {2,number} Affen pro Baum\n", array(4560, 123, 4560/123));
?>
The above example will output:
4,560 monkeys on 123 trees make 37.073 monkeys per tree 4.560 Affen auf 123 Bäumen sind 37,073 Affen pro Baum
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
MessageFormatter::format -- msgfmt_format — Format the message
Object oriented style
$args
) : stringProcedural style
Format the message by substituting the data into the format string according to the locale rules
fmtThe message formatter
argsArguments to insert into the format string
The formatted string, or FALSE if an error occurred
Example #1 msgfmt_format() example
<?php
$fmt = msgfmt_create("en_US", "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree");
echo msgfmt_format($fmt, array(4560, 123, 4560/123));
$fmt = msgfmt_create("de", "{0,number,integer} Affen auf {1,number,integer} Bäumen sind {2,number} Affen pro Baum");
echo msgfmt_format($fmt, array(4560, 123, 4560/123));
?>
Example #2 OO example
<?php
$fmt = new MessageFormatter("en_US", "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree");
echo $fmt->format(array(4560, 123, 4560/123));
$fmt = new MessageFormatter("de", "{0,number,integer} Affen auf {1,number,integer} Bäumen sind {2,number} Affen pro Baum");
echo $fmt->format(array(4560, 123, 4560/123));
?>
The above example will output:
4,560 monkeys on 123 trees make 37.073 monkeys per tree 4.560 Affen auf 123 Bäumen sind 37,073 Affen pro Baum
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
MessageFormatter::getErrorCode -- msgfmt_get_error_code — Get the error code from last operation
Object oriented style
Procedural style
Get the error code from last operation.
fmtThe message formatter
The error code, one of UErrorCode values. Initial value is U_ZERO_ERROR.
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
MessageFormatter::getErrorMessage -- msgfmt_get_error_message — Get the error text from the last operation
Object oriented style
Procedural style
Get the error text from the last operation.
fmtThe message formatter
Description of the last error.
Example #1 msgfmt_get_error_message() example
<?php
$fmt = msgfmt_create("en_US", "{0, number} monkeys on {1, number} trees");
$str = msgfmt_format($fmt, array());
if(!$str) {
echo "ERROR: ".msgfmt_get_error_message($fmt) . " (" . msgfmt_get_error_code($fmt) . ")\n";
}
?>
Example #2 OO example
<?php
$fmt = new MessageFormatter("en_US", "{0, number} monkeys on {1, number} trees");
$str = $fmt->format(array());
if(!$str) {
echo "ERROR: ".$fmt->getErrorMessage() . " (" . $fmt->getErrorCode() . ")\n";
}
?>
The above example will output:
ERROR: msgfmt_format: not enough parameters: U_ILLEGAL_ARGUMENT_ERROR (1)
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
MessageFormatter::getLocale -- msgfmt_get_locale — Get the locale for which the formatter was created
Object oriented style
Procedural style
Get the locale for which the formatter was created.
formatterThe formatter resource
The locale name
Example #1 msgfmt_get_locale() example
<?php
$fmt = msgfmt_create('en_US', "Number {0,number}");
echo msgfmt_get_locale($fmt);
?>
Example #2 OO example
<?php
$fmt = new MessageFormatter('en_US', "Number {0,number}");
echo $fmt->getLocale();
?>
The above example will output:
en_US
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
MessageFormatter::getPattern -- msgfmt_get_pattern — Get the pattern used by the formatter
Object oriented style
Procedural style
Get the pattern used by the formatter
fmtThe message formatter
The pattern string for this message formatter
Example #1 msgfmt_get_pattern() example
<?php
$fmt = msgfmt_create( "en_US", "{0, number} monkeys on {1, number} trees" );
echo "Default pattern: '" . msgfmt_get_pattern( $fmt ) . "'\n";
echo "Formatting result: " . msgfmt_format( $fmt, array(123, 456) ) . "\n";
msgfmt_set_pattern( $fmt, "{0, number} trees hosting {1, number} monkeys" );
echo "New pattern: '" . msgfmt_get_pattern( $fmt ) . "'\n";
echo "Formatted number: " . msgfmt_format( $fmt, array(123, 456) ) . "\n";
?>
Example #2 OO example
<?php
$fmt = new MessageFormatter( "en_US", "{0, number} monkeys on {1, number} trees" );
echo "Default pattern: '" . $fmt->getPattern() . "'\n";
echo "Formatting result: " . $fmt->format(array(123, 456)) . "\n";
$fmt->setPattern("{0, number} trees hosting {1, number} monkeys" );
echo "New pattern: '" . $fmt->getPattern() . "'\n";
echo "Formatted number: " . $fmt->format(array(123, 456)) . "\n";
?>
The above example will output:
Default pattern: '{0,number} monkeys on {1,number} trees'
Formatting result: 123 monkeys on 456 trees
New pattern: '{0,number} trees hosting {1,number} monkeys'
Formatted number: 123 trees hosting 456 monkeys
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
MessageFormatter::parseMessage -- msgfmt_parse_message — Quick parse input string
Object oriented style
$locale
, string $pattern
, string $source
) : arrayProcedural style
$locale
, string $pattern
, string $value
) : arrayParses input string without explicitly creating the formatter object. Use this function when the format operation is done only once and does not need and parameters or state to be kept.
localeThe locale to use for parsing locale-dependent parts
pattern
The pattern with which to parse the value.
source
The string to parse, conforming to the pattern.
An array containing items extracted, or FALSE on error
Example #1 msgfmt_parse_message() example
<?php
$fmt = msgfmt_parse_message('en_US', "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree",
"4,560 monkeys on 123 trees make 37.073 monkeys per tree");
var_export($fmt);
$fmt = msgfmt_parse_message('de', "{0,number,integer} Affen auf {1,number,integer} Bäumen sind {2,number} Affen pro Baum",
"4.560 Affen auf 123 Bäumen sind 37,073 Affen pro Baum");
var_export($fmt);
?>
Example #2 OO example
<?php
$fmt = MessageFormatter::parseMessage('en_US', "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree",
"4,560 monkeys on 123 trees make 37.073 monkeys per tree");
var_export($fmt);
$fmt = MessageFormatter::parseMessage('de', "{0,number,integer} Affen auf {1,number,integer} Bäumen sind {2,number} Affen pro Baum",
"4.560 Affen auf 123 Bäumen sind 37,073 Affen pro Baum");
var_export($fmt);
?>
The above example will output:
array (
0 => 4560,
1 => 123,
2 => 37.073,
)
array (
0 => 4560,
1 => 123,
2 => 37.073,
)
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
MessageFormatter::parse -- msgfmt_parse — Parse input string according to pattern
Object oriented style
$value
) : arrayProcedural style
Parses input string and return any extracted items as an array.
An array containing the items extracted, or FALSE on error
Example #1 msgfmt_parse() example
<?php
$fmt = msgfmt_create('en_US', "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree");
$res = msgfmt_parse($fmt, "4,560 monkeys on 123 trees make 37.073 monkeys per tree");
var_export($res);
$fmt = msgfmt_create('de', "{0,number,integer} Affen auf {1,number,integer} Bäumen sind {2,number} Affen pro Baum");
$res = msgfmt_parse($fmt, "4.560 Affen auf 123 Bäumen sind 37,073 Affen pro Baum");
var_export($res);
?>
Example #2 OO example
<?php
$fmt = new MessageFormatter('en_US', "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree");
$res = $fmt->parse("4,560 monkeys on 123 trees make 37.073 monkeys per tree");
var_export($res);
$fmt = new MessageFormatter('de', "{0,number,integer} Affen auf {1,number,integer} Bäumen sind {2,number} Affen pro Baum");
$res = $fmt->parse("4.560 Affen auf 123 Bäumen sind 37,073 Affen pro Baum");
var_export($res);
?>
The above example will output:
array (
0 => 4560,
1 => 123,
2 => 37.073,
)
array (
0 => 4560,
1 => 123,
2 => 37.073,
)
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
MessageFormatter::setPattern -- msgfmt_set_pattern — Set the pattern used by the formatter
Object oriented style
$pattern
) : boolProcedural style
Set the pattern used by the formatter
fmtThe message formatter
patternThe pattern string to use in this message formatter. The pattern uses an 'apostrophe-friendly' syntax; it is run through » umsg_autoQuoteApostrophe before being interpreted.
Returns TRUE on success or FALSE on failure.
Example #1 msgfmt_set_pattern() example
<?php
$fmt = msgfmt_create( "en_US", "{0, number} monkeys on {1, number} trees" );
echo "Default pattern: '" . msgfmt_get_pattern( $fmt ) . "'\n";
echo "Formatting result: " . msgfmt_format( $fmt, array(123, 456) ) . "\n";
msgfmt_set_pattern( $fmt, "{0, number} trees hosting {1, number} monkeys" );
echo "New pattern: '" . msgfmt_get_pattern( $fmt ) . "'\n";
echo "Formatted number: " . msgfmt_format( $fmt, array(123, 456) ) . "\n";
?>
Example #2 OO example
<?php
$fmt = new MessageFormatter( "en_US", "{0, number} monkeys on {1, number} trees" );
echo "Default pattern: '" . $fmt->getPattern() . "'\n";
echo "Formatting result: " . $fmt->format(array(123, 456)) . "\n";
$fmt->setPattern("{0, number} trees hosting {1, number} monkeys" );
echo "New pattern: '" . $fmt->getPattern() . "'\n";
echo "Formatted number: " . $fmt->format(array(123, 456)) . "\n";
?>
The above example will output:
Default pattern: '{0,number} monkeys on {1,number} trees'
Formatting result: 123 monkeys on 456 trees
New pattern: '{0,number} trees hosting {1,number} monkeys'
Formatted number: 123 trees hosting 456 monkeys
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
$key
, string $locale
, bool $commonlyUsed
) : Iterator$key
, string $locale
, bool $commonlyUsed
) : Iterator$year
, int $month
[, int $dayOfMonth = NULL
[, int $hour = NULL
[, int $minute = NULL
[, int $second = NULL
]]]] ) : bool$cal
, int $year
, int $month
[, int $dayOfMonth = NULL
[, int $hour = NULL
[, int $minute = NULL
[, int $second = NULL
]]]] ) : boolIntlCalendar::FIELD_ERA
Calendar field numerically representing an era, for instance
1 for AD and 0 for BC in the
Gregorian/Julian calendars and 235 for the Heisei
(平成) era in the Japanese calendar. Not all calendars have more than
one era.
IntlCalendar::FIELD_YEAR
Calendar field for the year. This is not unique across eras. If the
calendar type has more than one era, generally the minimum value for
this field will be 1.
IntlCalendar::FIELD_MONTH
Calendar field for the month. The month sequence is zero-based, so
January (here used to signify the first month of the calendar; this
may be called another name, such as Muharram in the Islamic calendar)
is represented by 0, February by
1, …, December by 11 and, for
calendars that have it, the 13th or leap month by
12.
IntlCalendar::FIELD_WEEK_OF_YEARCalendar field for the number of the week of the year. This depends on which day of the week is deemed to start the week and the minimal number of days in a week.
IntlCalendar::FIELD_WEEK_OF_MONTHCalendar field for the number of the week of the month. This depends on which day of the week is deemed to start the week and the minimal number of days in a week.
IntlCalendar::FIELD_DATE
Calendar field for the day of the month. The same as
IntlCalendar::FIELD_DAY_OF_MONTH, which has a
clearer name.
IntlCalendar::FIELD_DAY_OF_YEAR
Calendar field for the day of the year. For the Gregorian calendar,
starts with 1 and ends with
365 or 366.
IntlCalendar::FIELD_DAY_OF_WEEK
Calendar field for the day of the week. Its values start with
1 (Sunday, see IntlCalendar::DOW_SUNDAY
and subsequent constants) and the last valid value is 7 (Saturday).
IntlCalendar::FIELD_DAY_OF_WEEK_IN_MONTH
Given a day of the week (Sunday, Monday, …), this calendar
field assigns an ordinal to such a day of the week in a specific month.
Thus, if the value of this field is 1 and the value of the day of the
week is 2 (Monday), then the set day of the month is the 1st Monday of the
month; the maximum value is 5.
Additionally, the value 0 and negative values are
also allowed. The value 0 encompasses the seven days
that occur immediately before the first seven days of a month (which
therefore have a ‘day of week in month’ with value
1). Negative values starts counting from the end of
the month – -1 points to the last occurrence of a
day of the week in a month, -2 to the second last,
and so on.
Unlike IntlCalendar::FIELD_WEEK_OF_MONTH
and IntlCalendar::FIELD_WEEK_OF_YEAR,
this value does not depend on
IntlCalendar::getFirstDayOfWeek() or on
IntlCalendar::getMinimalDaysInFirstWeek(). The first
Monday is the first Monday, even if it occurs in a week that belongs to
the previous month.
IntlCalendar::FIELD_AM_PM
Calendar field indicating whether a time is before noon (value
0, AM) or after (1). Midnight is
AM, noon is PM.
IntlCalendar::FIELD_HOUR
Calendar field for the hour, without specifying whether itʼs in the
morning or in the afternoon. Valid values are 0 to
11.
IntlCalendar::FIELD_HOUR_OF_DAY
Calendar field for the full (24h) hour of the day. Valid values are
0 to 23.
IntlCalendar::FIELD_MINUTECalendar field for the minutes component of the time.
IntlCalendar::FIELD_SECONDCalendar field for the seconds component of the time.
IntlCalendar::FIELD_MILLISECONDCalendar field the milliseconds component of the time.
IntlCalendar::FIELD_ZONE_OFFSETCalendar field indicating the raw offset of the timezone, in milliseconds. The raw offset is the timezone offset, excluding any offset due to daylight saving time.
IntlCalendar::FIELD_DST_OFFSETCalendar field for the daylight saving time offset of the calendarʼs timezone, in milliseconds, if active for calendarʼs time.
IntlCalendar::FIELD_YEAR_WOYCalendar field representing the year for week of year purposes.
IntlCalendar::FIELD_DOW_LOCAL
Calendar field for the localized day of the week. This is a value
between 1 and 7,
1 being used for the day of the week that matches
the value returned by
IntlCalendar::getFirstDayOfWeek().
IntlCalendar::FIELD_EXTENDED_YEAR
Calendar field for a year number representation that is continuous
across eras. For the Gregorian calendar, the value of this field
matches that of IntlCalendar::FIELD_YEAR for AD
years; a BC year y is represented by -y +
1.
IntlCalendar::FIELD_JULIAN_DAYCalendar field for a modified Julian day number. It is different from a conventional Julian day number in that its transitions occur at local zone midnight rather than at noon UTC. It uniquely identifies a date.
IntlCalendar::FIELD_MILLISECONDS_IN_DAY
Calendar field encompassing the information in
IntlCalendar::FIELD_HOUR_OF_DAY,
IntlCalendar::FIELD_MINUTE,
IntlCalendar::FIELD_SECOND and
IntlCalendar::FIELD_MILLISECOND. Range is from the
0 to 24 * 3600 * 1000 - 1. It is
not the amount of milliseconds elapsed in the day since on DST
transitions it will have discontinuities analog to those of the wall
time.
IntlCalendar::FIELD_IS_LEAP_MONTH
Calendar field whose value is 1 for indicating a
leap month and 0 otherwise.
IntlCalendar::FIELD_FIELD_COUNTThe total number of fields.
IntlCalendar::FIELD_DAY_OF_MONTH
Alias for IntlCalendar::FIELD_DATE.
IntlCalendar::DOW_SUNDAYSunday.
IntlCalendar::DOW_MONDAYMonday.
IntlCalendar::DOW_TUESDAYTuesday.
IntlCalendar::DOW_WEDNESDAYWednesday.
IntlCalendar::DOW_THURSDAYThursday.
IntlCalendar::DOW_FRIDAYFriday.
IntlCalendar::DOW_SATURDAYSaturday.
IntlCalendar::DOW_TYPE_WEEKDAYOutput of IntlCalendar::getDayOfWeekType() indicating a day of week is a weekday.
IntlCalendar::DOW_TYPE_WEEKENDOutput of IntlCalendar::getDayOfWeekType() indicating a day of week belongs to the weekend.
IntlCalendar::DOW_TYPE_WEEKEND_OFFSETOutput of IntlCalendar::getDayOfWeekType() indicating the weekend begins during the given day of week.
IntlCalendar::DOW_TYPE_WEEKEND_CEASEOutput of IntlCalendar::getDayOfWeekType() indicating the weekend ends during the given day of week.
IntlCalendar::WALLTIME_FIRSTOutput of IntlCalendar::getSkippedWallTimeOption() indicating that wall times in the skipped range should refer to the same instant as wall times with one hour less and of IntlCalendar::getRepeatedWallTimeOption() indicating the wall times in the repeated range should refer to the instant of the first occurrence of such wall time.
IntlCalendar::WALLTIME_LASTOutput of IntlCalendar::getSkippedWallTimeOption() indicating that wall times in the skipped range should refer to the same instant as wall times with one hour after and of IntlCalendar::getRepeatedWallTimeOption() indicating the wall times in the repeated range should refer to the instant of the second occurrence of such wall time.
IntlCalendar::WALLTIME_NEXT_VALIDOutput of IntlCalendar::getSkippedWallTimeOption() indicating that wall times in the skipped range should refer to the instant when the daylight saving time transition occurs (begins).
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::add — Add a (signed) amount of time to a field
Object oriented style
$field
, int $amount
) : boolProcedural style
Add a signed amount to a field. Adding a positive amount allows advances in time, even if the numeric value of the field decreases (e.g. when working with years in BC dates).
Other fields may need to adjusted – for instance, adding a month to the 31st of January will result in the 28th (or 29th) of February. Contrary to IntlCalendar::roll(), when a value wraps around, more significant fields may change. For instance, adding a day to the 31st of January will result in the 1st of February, not the 1st of January.
calThe IntlCalendar resource.
field
One of the IntlCalendar date/time field constants. These are integer
values between 0 and
IntlCalendar::FIELD_COUNT.
amount
The signed amount to add to the current field. If the amount is positive,
the instant will be moved forward; if it is negative, the instant will be
moved into the past. The unit is implicit to the field type. For instance,
hours for IntlCalendar::FIELD_HOUR_OF_DAY.
Returns TRUE on success or FALSE on failure.
Example #1 IntlCalendar::add()
<?php
ini_set('intl.default_locale', 'fr_FR');
ini_set('date.timezone', 'UTC');
$cal = new IntlGregorianCalendar(2012, 0 /* January */, 31);
echo IntlDateFormatter::formatObject($cal), "\n";
$cal->add(IntlCalendar::FIELD_MONTH, 1);
echo IntlDateFormatter::formatObject($cal), "\n";
$cal->add(IntlCalendar::FIELD_DAY_OF_MONTH, 1);
echo IntlDateFormatter::formatObject($cal), "\n";
The above example will output:
31 janv. 2012 00:00:00 29 févr. 2012 00:00:00 1 mars 2012 00:00:00
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::after — Whether this objectʼs time is after that of the passed object
Object oriented style
Procedural style
Returns whether this objectʼs time succeeds the argumentʼs time.
calThe IntlCalendar resource.
otherThe calendar whose time will be checked against the primary objectʼs time.
Returns TRUE if this objectʼs current time is after that of the
calendar argumentʼs time. Returns FALSE otherwise.
Also returns FALSE on failure. You can use exceptions or
intl_get_error_code() to detect error conditions.
Example #1 IntlCalendar::after()
<?php
$cal1 = IntlCalendar::createInstance();
$cal2 = clone $cal1;
var_dump($cal1->after($cal2), //false
$cal2->after($cal1)); //false
$cal1->roll(IntlCalendar::FIELD_MILLISECOND, true);
var_dump($cal1->after($cal2), //true
$cal2->after($cal1)); //false
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::before — Whether this objectʼs time is before that of the passed object
Object oriented style
Procedural style
Returns whether this objectʼs time precedes the argumentʼs time.
calThe IntlCalendar resource.
otherThe calendar whose time will be checked against the primary objectʼs time.
Returns TRUE if this objectʼs current time is before that of the
calendar argumentʼs time. Returns FALSE otherwise.
Also returns FALSE on failure. You can use exceptions or
intl_get_error_code() to detect error conditions.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::clear — Clear a field or all fields
Object oriented style
$field = NULL
] ) : boolProcedural style
Clears either all of the fields or a specific field. A cleared field is
marked as unset, giving it the lowest priority against overlapping fields or
even default values when calculating the time. Additionally, its value is set
to 0, though given the fieldʼs low priority, its value may
have been internally set to another value by the time the field has finished
been queried.
calThe IntlCalendar resource.
field
One of the IntlCalendar date/time field constants. These are integer
values between 0 and
IntlCalendar::FIELD_COUNT.
Returns TRUE on success or FALSE on failure. Failure can only occur is
invalid arguments are provided.
Example #1 IntlCalendar::clear() examples
<?php
ini_set('intl.default_locale', 'es_ES');
ini_set('date.timezone', 'UTC');
$fields = array(
'FIELD_ERA' => 0,
'FIELD_YEAR' => 1,
'FIELD_MONTH' => 2,
'FIELD_WEEK_OF_YEAR' => 3,
'FIELD_WEEK_OF_MONTH' => 4,
'FIELD_DATE' => 5,
'FIELD_DAY_OF_YEAR' => 6,
'FIELD_DAY_OF_WEEK' => 7,
'FIELD_DAY_OF_WEEK_IN_MONTH' => 8,
'FIELD_AM_PM' => 9,
'FIELD_HOUR' => 10,
'FIELD_HOUR_OF_DAY' => 11,
'FIELD_MINUTE' => 12,
'FIELD_SECOND' => 13,
'FIELD_MILLISECOND' => 14,
'FIELD_ZONE_OFFSET' => 15,
'FIELD_DST_OFFSET' => 16,
'FIELD_YEAR_WOY' => 17,
'FIELD_DOW_LOCAL' => 18,
'FIELD_EXTENDED_YEAR' => 19,
'FIELD_JULIAN_DAY' => 20,
'FIELD_MILLISECONDS_IN_DAY' => 21,
'FIELD_IS_LEAP_MONTH' => 22,
'FIELD_FIELD_COUNT' => 23,
);
function getSetFields(IntlCalendar $cal) {
global $fields;
$ret = array();
foreach ($fields as $name => $value) {
if ($cal->isSet($value)) {
$ret[] = $name;
}
}
return $ret;
}
$cal = new IntlGregorianCalendar(2013, 2 /* March */, 15);
echo "After GregorianCalendar creation\n";
print_r(getSetFields($cal));
echo "\n";
echo IntlDateFormatter::formatObject($cal), "\n";
echo "After the formatter requested the extended year\n";
print_r(getSetFields($cal));
echo "\n";
$cal->clear(IntlCalendar::FIELD_YEAR);
echo "After the year has been cleared, the date stays the same\n";
echo IntlDateFormatter::formatObject($cal), "\n";
echo "because FIELD_EXTENDED_YEAR is still set\n";
print_r(getSetFields($cal));
echo "\n";
var_dump($cal->clear(IntlCalendar::FIELD_EXTENDED_YEAR));
echo "After the extended year has been cleared\n";
print_r(getSetFields($cal));
echo IntlDateFormatter::formatObject($cal), "\n";
echo "\n";
echo "After the fields are recalculated,\n"
. " extended year is set again (to 1970)\n";
print_r(getSetFields($cal));
echo "\n";
$cal->clear();
echo "After calling variant with no arguments\n";
print_r(getSetFields($cal));
echo IntlDateFormatter::formatObject($cal), "\n";
The above example will output:
After GregorianCalendar creation
Array
(
[0] => FIELD_ERA
[1] => FIELD_YEAR
[2] => FIELD_MONTH
[3] => FIELD_DATE
)
15/03/2013 00:00:00
After the formatter requested the extended year
Array
(
[0] => FIELD_ERA
[1] => FIELD_YEAR
[2] => FIELD_MONTH
[3] => FIELD_DATE
[4] => FIELD_EXTENDED_YEAR
)
After the year has been cleared, the date stays the same
15/03/2013 00:00:00
because FIELD_EXTENDED_YEAR is still set
Array
(
[0] => FIELD_ERA
[1] => FIELD_MONTH
[2] => FIELD_DATE
[3] => FIELD_EXTENDED_YEAR
)
bool(true)
After the extended year has been cleared
Array
(
[0] => FIELD_ERA
[1] => FIELD_MONTH
[2] => FIELD_DATE
)
15/03/1970 00:00:00
After the fields are recalculated,
extended year is set again (to 1970)
Array
(
[0] => FIELD_ERA
[1] => FIELD_MONTH
[2] => FIELD_DATE
[3] => FIELD_EXTENDED_YEAR
)
After calling variant with no arguments
Array
(
)
01/01/1970 00:00:00
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::__construct — Private constructor for disallowing instantiation
A private constructor for disallowing instantiation with the new operator.
Call IntlCalendar::createInstance() instead.
This function has no parameters.
No value is returned.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::createInstance — Create a new IntlCalendar
Object oriented style
$timeZone = NULL
[, string $locale = ""
]] ) : IntlCalendarProcedural style
Given a timezone and locale, this method creates an IntlCalendar object. This factory method may return a subclass of IntlCalendar.
The calendar created will represent the time instance at which it was created, based on the system time. The fields can all be cleared by calling IntCalendar::clear() with no arguments. See also IntlGregorianCalendar::__construct().
timeZoneThe timezone to use.
NULL, in which case the default timezone will be used, as specified in
the ini setting date.timezone or
through the function date_default_timezone_set() and as
returned by date_default_timezone_get().
An IntlTimeZone, which will be used directly.
A DateTimeZone. Its identifier will be extracted and an ICU timezone object will be created; the timezone will be backed by ICUʼs database, not PHPʼs.
A string, which should be a valid ICU timezone identifier.
See IntlTimeZone::createTimeZoneIDEnumeration(). Raw
offsets such as "GMT+08:30" are also accepted.
locale
A locale to use or NULL to use the default locale.
The created IntlCalendar instance or NULL on
failure.
Example #1 IntlCalendar::createInstance()
<?php
ini_set('intl.default_locale', 'es_ES');
ini_set('date.timezone', 'Europe/Madrid');
$cal = IntlCalendar::createInstance();
echo "No arguments\n";
var_dump(get_class($cal),
IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL));
echo "\n";
echo "Explicit timezone\n";
$cal = IntlCalendar::createInstance(IntlTimeZone::getGMT());
var_dump(get_class($cal),
IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL));
echo "\n";
echo "Explicit locale (with calendar)\n";
$cal = IntlCalendar::createInstance(NULL, 'es_ES@calendar=persian');
var_dump(get_class($cal),
IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL));
The above example will output:
No arguments string(21) "IntlGregorianCalendar" string(68) "martes 18 de junio de 2013 14:11:02 Hora de verano de Europa Central" Explicit timezone string(21) "IntlGregorianCalendar" string(45) "martes 18 de junio de 2013 12:11:02 GMT+00:00" Explicit locale (with calendar) string(12) "IntlCalendar" string(70) "martes 28 de Khordad de 1392 14:11:02 Hora de verano de Europa Central"
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::equals — Compare time of two IntlCalendar objects for equality
Object oriented style
Procedural style
Returns true if this calendar and the given calendar have the same time. The settings, calendar types and field states do not have to be the same.
calThe IntlCalendar resource.
otherThe calendar to compare with the primary object.
Returns TRUE if the current time of both this and the passed in
IntlCalendar object are the same, or FALSE
otherwise. The value FALSE can also be returned on failure. This can only
happen if bad arguments are passed in. In any case, the two cases can be
distinguished by calling intl_get_error_code().
Example #1 IntlCalendar::equals()
<?php
ini_set('date.timezone', 'UTC');
$cal1 = IntlCalendar::createInstance(NULL, 'es_ES');
$cal2 = clone $cal1;
var_dump($cal1->equals($cal2)); //TRUE
//The locale is not included in the comparison
$cal2 = IntlCalendar::createInstance(NULL, 'pt_PT');
$cal2->setTime($cal1->getTime());
var_dump($cal1->equals($cal2)); //TRUE
//And set fields state is not included as well
$cal2->clear(IntlCalendar::FIELD_YEAR);
var_dump($cal1->isSet(IntlCalendar::FIELD_YEAR) ==
$cal2->isSet(IntlCalendar::FIELD_YEAR)); //FALSE
var_dump($cal1->equals($cal2)); //TRUE
//Neither is the calendar type
$cal2 = IntlCalendar::createInstance(NULL, 'es_ES@calendar=islamic');
$cal2->setTime($cal1->getTime());
var_dump($cal1->equals($cal2)); //TRUE
//Only the time is
$cal2 = clone $cal1;
$cal2->setTime($cal1->getTime() + 1.);
var_dump($cal1->equals($cal2)); //FALSE
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::fieldDifference — Calculate difference between given time and this objectʼs time
Object oriented style
$when
, int $field
) : intProcedural style
Return the difference between the given time and the time this object is
set to, with respect to the quantity specified the
field parameter.
This method is meant to be called successively, first with the most significant field of interest down to the least significant field. To this end, as a side effect, this calendarʼs value for the field specified is advanced by the amount returned.
calThe IntlCalendar resource.
when
The time against which to compare the quantity represented by the
field. For the result to be positive, the time
given for this parameter must be ahead of the time of the object the
method is being invoked on.
fieldThe field that represents the quantity being compared.
One of the IntlCalendar date/time field constants. These are integer
values between 0 and
IntlCalendar::FIELD_COUNT.
Returns a (signed) difference of time in the unit associated with the
specified field or FALSE on failure.
Example #1 IntlCalendar::fieldDifference()
<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'fr_FR');
$cal1 = IntlCalendar::fromDateTime('2012-02-29 09:00:11');
$cal2 = IntlCalendar::fromDateTime('2013-03-01 09:19:29');
$time = $cal2->getTime();
echo "Time before: ", IntlDateFormatter::formatObject($cal1), "\n";
printf(
"The difference in time is %d year(s), %d month(s), "
. "%d day(s), %d hour(s) and %d minute(s)\n",
$cal1->fieldDifference($time, IntlCalendar::FIELD_YEAR),
$cal1->fieldDifference($time, IntlCalendar::FIELD_MONTH),
$cal1->fieldDifference($time, IntlCalendar::FIELD_DAY_OF_MONTH),
$cal1->fieldDifference($time, IntlCalendar::FIELD_HOUR_OF_DAY),
$cal1->fieldDifference($time, IntlCalendar::FIELD_MINUTE)
);
//now it was advanced to the target time, exception for the seconds,
//for which we did not measure the difference
echo "Time after: ", IntlDateFormatter::formatObject($cal1), "\n";
The above example will output:
Time before: 29 févr. 2012 09:00:11 The difference in time is 1 year(s), 0 month(s), 1 day(s), 0 hour(s) and 19 minute(s) Time after: 1 mars 2013 09:19:11
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a2)
IntlCalendar::fromDateTime — Create an IntlCalendar from a DateTime object or string
Object oriented style
Procedural style
Creates an IntlCalendar object either from a DateTime object or from a string from which a DateTime object can be built.
The new calendar will represent not only the same instant as the given DateTime (subject to precision loss for dates very far into the past or future), but also the same timezone (subject to the caveat that different timezone databases will be used, and therefore the results may differ).
dateTimeA DateTime object or a string that can be passed to DateTime::__construct().
The created IntlCalendar object or NULL in case of
failure. If a string is passed, any exception that occurs
inside the DateTime constructor is propagated.
Example #1 IntlCalendar::fromDateTime()
<?php
ini_set('date.timezone', 'Europe/Lisbon');
//same as IntlCalendar::fromDateTime(new DateTime(...))
$cal1 = IntlCalendar::fromDateTime('2013-02-28 00:01:02 Europe/Berlin');
//Note the timezone is Europe/Berlin, not the default Europe/Lisbon
echo IntlDateFormatter::formatObject($cal1, 'yyyy MMMM d HH:mm:ss VVVV', 'de_DE'), "\n";
The above example will output:
2013 Februar 28 00:01:02 Deutschland Zeit
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::get — Get the value for a field
Object oriented style
$field
) : intProcedural style
Gets the value for a specific field.
calThe IntlCalendar resource.
field
One of the IntlCalendar date/time field constants. These are integer
values between 0 and
IntlCalendar::FIELD_COUNT.
An integer with the value of the time field.
Example #1 IntlCalendar::get()
<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'en_US');
$class = new ReflectionClass('IntlCalendar');
$fields = array();
foreach ($class->getConstants() as $name => $val) {
if (strpos($name, 'FIELD_') !== 0 || $val > 22)
continue;
$fields[$val] = $name;
}
$cal = IntlCalendar::createInstance(); // current time
var_dump(IntlDateFormatter::formatObject($cal));
foreach ($fields as $val => $name) {
echo "$val ($name)", "\n ", $cal->get($val), "\n";
}
The above example will output:
string(23) "Jul 1, 2013, 4:44:44 AM"
0 (FIELD_ERA)
1
1 (FIELD_YEAR)
2013
2 (FIELD_MONTH)
6
3 (FIELD_WEEK_OF_YEAR)
27
4 (FIELD_WEEK_OF_MONTH)
1
5 (FIELD_DAY_OF_MONTH)
1
6 (FIELD_DAY_OF_YEAR)
182
7 (FIELD_DAY_OF_WEEK)
2
8 (FIELD_DAY_OF_WEEK_IN_MONTH)
1
9 (FIELD_AM_PM)
0
10 (FIELD_HOUR)
4
11 (FIELD_HOUR_OF_DAY)
4
12 (FIELD_MINUTE)
44
13 (FIELD_SECOND)
44
14 (FIELD_MILLISECOND)
551
15 (FIELD_ZONE_OFFSET)
0
16 (FIELD_DST_OFFSET)
3600000
17 (FIELD_YEAR_WOY)
2013
18 (FIELD_DOW_LOCAL)
2
19 (FIELD_EXTENDED_YEAR)
2013
20 (FIELD_JULIAN_DAY)
2456475
21 (FIELD_MILLISECONDS_IN_DAY)
17084551
22 (FIELD_IS_LEAP_MONTH)
0
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::getActualMaximum — The maximum value for a field, considering the objectʼs current time
Object oriented style
$field
) : intProcedural style
Returns a fieldʼs relative maximum value around the current time. The exact semantics vary by field, but in the general case this is the value that would be obtained if one would set the field value into the smallest relative maximum for the field and would increment it until reaching the global maximum or the field value wraps around, in which the value returned would be the global maximum or the value before the wrapping, respectively.
For instance, in the gregorian calendar, the actual maximum value for the
day of
month would vary between 28 and
31, depending on the month and year of the current time.
calThe IntlCalendar resource.
field
One of the IntlCalendar date/time field constants. These are integer
values between 0 and
IntlCalendar::FIELD_COUNT.
An int representing the maximum value in the units associated
with the given field or FALSE on failure.
Example #1 IntlCalendar::getActualMaximum()
<?php
ini_set('date.timezone', 'Europe/Lisbon');
$cal = IntlCalendar::fromDateTime('2013-02-15');
var_dump($cal->getActualMaximum(IntlCalendar::FIELD_DAY_OF_MONTH)); //28
$cal->add(IntlCalendar::FIELD_EXTENDED_YEAR, -1);
var_dump($cal->getActualMaximum(IntlCalendar::FIELD_DAY_OF_MONTH)); //29
The above example will output:
int(28) int(29)
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::getActualMinimum — The minimum value for a field, considering the objectʼs current time
Object oriented style
$field
) : intProcedural style
Returns a fieldʼs relative minimum value around the current time. The exact semantics vary by field, but in the general case this is the value that would be obtained if one would set the field value into the greatest relative minimum for the field and would decrement it until reaching the global minimum or the field value wraps around, in which the value returned would be the global minimum or the value before the wrapping, respectively.
For the Gregorian calendar, this is always the same as IntlCalendar::getMinimum().
calThe IntlCalendar resource.
field
One of the IntlCalendar date/time field constants. These are integer
values between 0 and
IntlCalendar::FIELD_COUNT.
An int representing the minimum value in the fieldʼs
unit or FALSE on failure.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::getAvailableLocales — Get array of locales for which there is data
Object oriented style
Procedural style
Gives the list of locales for which calendars are installed. As of ICU 51, this is the list of all installed ICU locales.
This function has no parameters.
Example #1 IntlCalendar::getAvailableLocales()
<?php
print_r(IntlCalendar::getAvailableLocales());
The above example will output:
Array
(
[0] => af
[1] => af_NA
[2] => af_ZA
[3] => agq
[4] => agq_CM
[5] => ak
[6] => ak_GH
[7] => am
[8] => am_ET
[9] => ar
[10] => ar_001
[11] => ar_AE
[12] => ar_BH
[13] => ar_DJ
… output abbreviated …
[595] => zh_Hant_HK
[596] => zh_Hant_MO
[597] => zh_Hant_TW
[598] => zu
[599] => zu_ZA
)
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::getDayOfWeekType — Tell whether a day is a weekday, weekend or a day that has a transition between the two
Object oriented style
$dayOfWeek
) : intProcedural style
Returns whether the passed day is a weekday
(IntlCalendar::DOW_TYPE_WEEKDAY), a weekend day
(IntlCalendar::DOW_TYPE_WEEKEND), a day during which a
transition occurs into the weekend
(IntlCalendar::DOW_TYPE_WEEKEND_OFFSET) or a day during
which the weekend ceases
(IntlCalendar::DOW_TYPE_WEEKEND_CEASE).
If the return is either
IntlCalendar::DOW_TYPE_WEEKEND_OFFSET or
IntlCalendar::DOW_TYPE_WEEKEND_CEASE, then
IntlCalendar::getWeekendTransition() can be called to
obtain the time of the transition.
This function requires ICU 4.4 or later.
calThe IntlCalendar resource.
dayOfWeek
One of the constants IntlCalendar::DOW_SUNDAY,
IntlCalendar::DOW_MONDAY, …,
IntlCalendar::DOW_SATURDAY.
Returns one of the constants
IntlCalendar::DOW_TYPE_WEEKDAY,
IntlCalendar::DOW_TYPE_WEEKEND,
IntlCalendar::DOW_TYPE_WEEKEND_OFFSET or
IntlCalendar::DOW_TYPE_WEEKEND_CEASE or FALSE on failure.
Example #1 IntlCalendar::getDayOfWeekType()
<?php
foreach (array('en_US', 'ar_SA') as $locale) {
echo "Locale: ", Locale::getDisplayName($locale, "en_US"), "\n";
$cal = IntlCalendar::createInstance('UTC', $locale);
for ($i = IntlCalendar::DOW_SUNDAY; $i <= IntlCalendar::DOW_SATURDAY; $i++) {
echo $i, " ", $cal->getDayOfWeekType($i), " ",
$cal->getDayOfWeekType($i) >= IntlCalendar::DOW_TYPE_WEEKEND_OFFSET
? $cal->getWeekendTransition($i)
: '',
"\n";
}
echo "\n";
}
The above example will output:
Locale: English (United States) 1 3 86400000 2 0 3 0 4 0 5 0 6 0 7 1 Locale: Arabic (Saudi Arabia) 1 0 2 0 3 0 4 0 5 1 6 3 86400000 7 0
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::getErrorCode -- intlcal_get_error_code — Get last error code on the object
Object oriented style (method):
Procedural style:
Returns the numeric ICU error code for the last call on this object
(including cloning) or the IntlCalendar given for
the calendar parameter (in the procedural‒style
version). This may indicate only a warning (negative error code) or no
error at all (U_ZERO_ERROR). The actual presence of an
error can be tested with intl_is_failure().
Invalid arguments detected on the PHP side (before invoking functions of the ICU library) are not recorded for the purposes of this function.
The last error that occurred in any call to a function of the intl extension, including early argument errors, can be obtained with intl_get_error_code(). This function resets the global error code, but not the objectʼs error code.
calendarThe calendar object, on the procedural style interface.
An ICU error code indicating either success, failure or a warning.
Example #1 IntlCalendar::getErrorCode() and IntlCalendar::getErrorMessage()
<?php
ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "nl");
$intlcal = new IntlGregorianCalendar(2012, 1, 29);
var_dump(
$intlcal->getErrorCode(),
$intlcal->getErrorMessage()
);
$intlcal->fieldDifference(-1e100, IntlCalendar::FIELD_SECOND);
var_dump(
$intlcal->getErrorCode(),
$intlcal->getErrorMessage()
);
The above example will output:
int(0) string(12) "U_ZERO_ERROR" Warning: IntlCalendar::fieldDifference(): intlcal_field_difference: Call to ICU method has failed in /home/glopes/php/ws/example.php on line 10 int(1) string(81) "intlcal_field_difference: Call to ICU method has failed: U_ILLEGAL_ARGUMENT_ERROR"
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::getErrorMessage -- intlcal_get_error_message — Get last error message on the object
Object oriented style (method):
Procedural style:
Returns the error message (if any) associated with the error reported by IntlCalendar::getErrorCode() or intlcal_get_error_code(). If there is no associated error message, only the string representation of the name of the error constant will be returned. Otherwise, the message also includes a message set on the side of the PHP binding.
calendarThe calendar object, on the procedural style interface.
The error message associated with last error that occurred in a function call on this object, or a string indicating the non-existance of an error.
Example #1 IntlCalendar::getErrorMessage()
<?php
$cal = IntlCalendar::createInstance('UTC', 'en_US');
var_dump($cal->getErrorMessage());
$cal->getWeekendTransition(IntlCalendar::DOW_WEDNESDAY);
var_dump($cal->getErrorMessage());
The above example will output:
string(12) "U_ZERO_ERROR" string(82) "intlcal_get_weekend_transition: Error calling ICU method: U_ILLEGAL_ARGUMENT_ERROR"
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::getFirstDayOfWeek — Get the first day of the week for the calendarʼs locale
Object oriented style
Procedural style
The week day deemed to start a week, either the default value for this locale or the value set with IntlCalendar::setFirstDayOfWeek().
calThe IntlCalendar resource.
One of the constants IntlCalendar::DOW_SUNDAY,
IntlCalendar::DOW_MONDAY, …,
IntlCalendar::DOW_SATURDAY or FALSE on failure.
Example #1 IntlCalendar::getFirstDayOfWeek()
<?php
ini_set('date.timezone', 'UTC');
$cal1 = IntlCalendar::createInstance(NULL, 'es_ES');
var_dump($cal1->getFirstDayOfWeek()); // Monday
$cal1->set(2013, 1 /* February */, 3); // a Sunday
var_dump($cal1->get(IntlCalendar::FIELD_WEEK_OF_YEAR)); // 5
$cal2 = IntlCalendar::createInstance(NULL, 'en_US');
var_dump($cal2->getFirstDayOfWeek()); // Sunday
$cal2->set(2013, 1 /* February */, 3); // a Sunday
var_dump($cal2->get(IntlCalendar::FIELD_WEEK_OF_YEAR)); // 6
The above example will output:
int(2) int(5) int(1) int(6)
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::getGreatestMinimum — Get the largest local minimum value for a field
Object oriented style
$field
) : intProcedural style
Returns the largest local minimum for a field. This should be a value larger or equal to that returned by IntlCalendar::getActualMinimum(), which is in its turn larger or equal to that returned by IntlCalendar::getMinimum(). All these three functions return the same value for the Gregorian calendar.
calThe IntlCalendar resource.
field
One of the IntlCalendar date/time field constants. These are integer
values between 0 and
IntlCalendar::FIELD_COUNT.
An int representing a field value, in the fieldʼs
unit, or FALSE on failure.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::getKeywordValuesForLocale — Get set of locale keyword values
Object oriented style
$key
, string $locale
, bool $commonlyUsed
) : IteratorProcedural style
$key
, string $locale
, bool $commonlyUsed
) : Iterator
For a given locale key, get the set of values for that key that would result
in a different behavior. For now, only the 'calendar'
keyword is supported.
This function requires ICU 4.2 or later.
key
The locale keyword for which relevant values are to be queried. Only
'calendar' is supported.
localeThe locale onto which the keyword/value pair are to be appended.
commonlyUsedWhether to show only the values commonly used for the specified locale.
An iterator that yields strings with the locale keyword
values or FALSE on failure.
Example #1 IntlCalendar::getKeyworkValuesForLocale()
<?php
print_r(
iterator_to_array(
IntlCalendar::getKeywordValuesForLocale(
'calendar', 'fa_IR', true)));
print_r(
iterator_to_array(
IntlCalendar::getKeywordValuesForLocale(
'calendar', 'fa_IR', false)));
The above example will output:
Array
(
[0] => persian
[1] => gregorian
[2] => islamic
[3] => islamic-civil
)
Array
(
[0] => persian
[1] => gregorian
[2] => islamic
[3] => islamic-civil
[4] => japanese
[5] => buddhist
[6] => roc
[7] => hebrew
[8] => chinese
[9] => indian
[10] => coptic
[11] => ethiopic
[12] => ethiopic-amete-alem
)
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::getLeastMaximum — Get the smallest local maximum for a field
Object oriented style
$field
) : intProcedural style
Returns the smallest local maximumw for a field. This should be a value smaller or equal to that returned by IntlCalendar::getActualMaxmimum(), which is in its turn smaller or equal to that returned by IntlCalendar::getMaximum().
calThe IntlCalendar resource.
field
One of the IntlCalendar date/time field constants. These are integer
values between 0 and
IntlCalendar::FIELD_COUNT.
An int representing a field value in the fieldʼs
unit or FALSE on failure.
Example #1 Maxima examples
<?php
ini_set('date.timezone', 'UTC');
ini_set('intl.default_locale', 'it_IT');
$cal = new IntlGregorianCalendar(2013, 3 /* April */, 6);
var_dump(
$cal->getLeastMaximum(IntlCalendar::FIELD_DAY_OF_MONTH), // 28
$cal->getActualMaximum(IntlCalendar::FIELD_DAY_OF_MONTH), // 30
$cal->getMaximum(IntlCalendar::FIELD_DAY_OF_MONTH) // 31
);
The above example will output:
int(28) int(30) int(31)
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::getLocale — Get the locale associated with the object
Object oriented style
$localeType
) : stringProcedural style
Returns the locale used by this calendar object.
calThe IntlCalendar resource.
localeType
Whether to fetch the actual locale (the locale from which the calendar
data originates, with Locale::ACTUAL_LOCALE) or the
valid locale, i.e., the most specific locale supported by ICU relatively
to the requested locale – see Locale::VALID_LOCALE.
From the most general to the most specific, the locales are ordered in
this fashion – actual locale, valid locale, requested locale.
A locale string or FALSE on failure.
Example #1 IntlCalendar::getLocale()
<?php
$cal = IntlCalendar::createInstance(IntlTimeZone::getGMT(), 'en_US_CALIFORNIA');
var_dump(
$cal->getLocale(Locale::ACTUAL_LOCALE),
$cal->getLocale(Locale::VALID_LOCALE)
);
The above example will output:
string(2) "en" string(5) "en_US"
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::getMaximum — Get the global maximum value for a field
Object oriented style
$field
) : intProcedural style
Gets the global maximum for a field, in this specific calendar. This value is larger or equal to that returned by IntlCalendar::getActualMaximum(), which is in its turn larger or equal to that returned by IntlCalendar::getLeastMaximum().
calThe IntlCalendar resource.
field
One of the IntlCalendar date/time field constants. These are integer
values between 0 and
IntlCalendar::FIELD_COUNT.
An int representing a field value in the fieldʼs
unit or FALSE on failure.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::getMinimalDaysInFirstWeek — Get minimal number of days the first week in a year or month can have
Object oriented style
Procedural style
Returns the smallest number of days the first week of a year or month must have in the new year or month. For instance, in the Gregorian calendar, if this value is 1, then the first week of the year will necessarily include January 1st, while if this value is 7, then the week with January 1st will be the first week of the year only if the day of the week for January 1st matches the day of the week returned by IntlCalendar::getFirstDayOfWeek(); otherwise it will be the previous yearʼs last week.
calThe IntlCalendar resource.
An int representing a number of days or FALSE on failure.
Example #1 IntlCalendar::getMinimalDaysInFirstWeek()
<?php
ini_set('date.timezone', 'UTC');
ini_set('intl.default_locale', 'en_US');
$cal = new IntlGregorianCalendar(2013, 0 /* January */, 2);
var_dump(IntlDateFormatter::formatObject($cal, 'cccc')); // Wednesday
var_dump($cal->getMinimalDaysInFirstWeek(), // 1
$cal->getFirstDayofWeek()); // 1 (Sunday)
// Week 1 of 2013
var_dump(IntlDateFormatter::formatObject($cal, "'Week 'w' of 'Y"));
$cal->setMinimalDaysInFirstWeek(4);
// Still Week 1 of 2013 (1st week has 5 days in the new year)
var_dump(IntlDateFormatter::formatObject($cal, "'Week 'w' of 'Y"));
$cal->setMinimalDaysInFirstWeek(6);
// Week 53 of 2012
var_dump(IntlDateFormatter::formatObject($cal, "'Week 'w' of 'Y"));
The above example will output:
string(9) "Wednesday" int(1) int(1) string(14) "Week 1 of 2013" string(14) "Week 1 of 2013" string(15) "Week 53 of 2012"
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::getMinimum — Get the global minimum value for a field
Object oriented style
$field
) : intProcedural style
Gets the global minimum for a field, in this specific calendar. This value is smaller or equal to that returned by IntlCalendar::getActualMinimum(), which is in its turn smaller or equal to that returned by IntlCalendar::getGreatestMinimum(). For the Gregorian calendar, these three functions always return the same value (for each field).
calThe IntlCalendar resource.
field
One of the IntlCalendar date/time field constants. These are integer
values between 0 and
IntlCalendar::FIELD_COUNT.
An int representing a value for the given
field in the fieldʼs unit or FALSE on failure.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::getNow — Get number representing the current time
Object oriented style
Procedural style
The number of milliseconds that have passed since the reference date. This number is derived from the system time.
This function has no parameters.
A float representing a number of milliseconds since the epoch, not counting leap seconds.
Example #1 IntlCalendar::getNow()
<?php
$formatter = IntlDateFormatter::create('es_ES',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'Europe/Madrid');
$val = IntlCalendar::getNow();
var_dump($val);
echo $formatter->format(IntlCalendar::getNow() / 1000.), "\n";
The above example will output:
float(1371425814666) lunes, 17 de junio de 2013 01:36:54 Hora de verano de Europa central
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::getRepeatedWallTimeOption — Get behavior for handling repeating wall time
Object oriented style
Procedural style
Gets the current strategy for dealing with wall times that are repeated
whenever the clock is set back during dailight saving time end transitions.
The default value is IntlCalendar::WALLTIME_LAST.
This function requires ICU 4.9 or later.
calThe IntlCalendar resource.
One of the constants IntlCalendar::WALLTIME_FIRST or
IntlCalendar::WALLTIME_LAST.
Example #1 IntlCalendar::getRepeatedWallTimeOption()
<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'en_US');
ini_set('intl.error_level', E_WARNING);
//On October 27th at 0200, the clock goes back 1 hour and from GMT+01 to GMT+00
$cal = new IntlGregorianCalendar(2013, 9 /* October */, 27, 1, 30);
var_dump($cal->getRepeatedWalltimeOption()); // 0 WALLTIME_LAST
$formatter = IntlDateFormatter::create(
NULL,
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'UTC'
);
var_dump($formatter->format($cal->getTime() / 1000.));
$cal->setRepeatedWalltimeOption(IntlCalendar::WALLTIME_FIRST);
var_dump($cal->getRepeatedWalltimeOption()); // 1 WALLTIME_FIRST
$cal->set(IntlCalendar::FIELD_HOUR_OF_DAY, 1);
var_dump($formatter->format($cal->getTime() / 1000.));
The above example will output:
int(0) string(42) "Sunday, October 27, 2013 at 1:30:00 AM GMT" int(1) string(43) "Sunday, October 27, 2013 at 12:30:00 AM GMT"
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::getSkippedWallTimeOption — Get behavior for handling skipped wall time
Object oriented style
Procedural style
Gets the current strategy for dealing with wall times that are skipped
whenever the clock is forwarded during dailight saving time start transitions.
The default value is IntlCalendar::WALLTIME_LAST.
The calendar must be lenient for this option to have any effect, otherwise attempting to set a non-existing time will cause an error.
This function requires ICU 4.9 or later.
calThe IntlCalendar resource.
One of the constants IntlCalendar::WALLTIME_FIRST,
IntlCalendar::WALLTIME_LAST or
IntlCalendar::WALLTIME_NEXT_VALID.
Example #1 IntlCalendar::getSkippedWallTimeOption()
<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'en_US');
ini_set('intl.error_level', E_WARNING);
//On March 31st at 0100, the clock goes forward 1 hour and from GMT+00 to GMT+01
$cal = new IntlGregorianCalendar(2013, 2 /* March */, 31, 1, 30);
var_dump(
$cal->isLenient(), // true
$cal->getSkippedWalltimeOption() // 0 WALLTIME_LAST
);
$formatter = IntlDateFormatter::create(
NULL,
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'UTC'
);
var_dump($formatter->format($cal->getTime() / 1000));
$cal->setSkippedWallTimeOption(IntlCalendar::WALLTIME_FIRST);
var_dump($cal->getSkippedWalltimeOption()); // 1 WALLTIME_FIRST
$cal->set(IntlCalendar::FIELD_HOUR_OF_DAY, 1);
var_dump($formatter->format($cal->getTime() / 1000));
$cal->setSkippedWallTimeOption(IntlCalendar::WALLTIME_NEXT_VALID);
var_dump($cal->getSkippedWalltimeOption()); // 2 WALLTIME_NEXT_VALID
$cal->set(IntlCalendar::FIELD_HOUR_OF_DAY, 1);
var_dump($formatter->format($cal->getTime() / 1000));
The above example will output:
bool(true) int(0) string(40) "Sunday, March 31, 2013 at 1:30:00 AM GMT" int(1) string(41) "Sunday, March 31, 2013 at 12:30:00 AM GMT" int(2) string(40) "Sunday, March 31, 2013 at 1:00:00 AM GMT"
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::getTime — Get time currently represented by the object
Object oriented style
Procedural style
Returns the time associated with this object, expressed as the number of milliseconds since the epoch.
calThe IntlCalendar resource.
A float representing the number of milliseconds elapsed since the reference time (1 Jan 1970 00:00:00 UTC).
Example #1 IntlCalendar::getTime()
<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'en_US');
$cal = new IntlGregorianCalendar(2013, 4 /* May */, 1, 0, 0, 0);
$time = $cal->getTime();
var_dump($time, $time / 1000 == strtotime('2013-05-01 00:00:00')); //true
The above example will output:
float(1367362800000) bool(true)
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::getTimeZone — Get the objectʼs timezone
Object oriented style
Procedural style
Returns the IntlTimeZone object associated with this calendar.
calThe IntlCalendar resource.
An IntlTimeZone object corresponding to the one used internally in this object.
Example #1 IntlCalendar::getTimeZone()
<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'en_US');
$cal = IntlCalendar::createInstance();
print_r($cal->getTimeZone());
$cal->setTimeZone('UTC');
print_r($cal->getTimeZone());
$cal = IntlCalendar::fromDateTime('2012-01-01 00:00:00 GMT+03:33');
print_r($cal->getTimeZone());
The above example will output:
IntlTimeZone Object
(
[valid] => 1
[id] => Europe/Lisbon
[rawOffset] => 0
[currentOffset] => 3600000
)
IntlTimeZone Object
(
[valid] => 1
[id] => UTC
[rawOffset] => 0
[currentOffset] => 0
)
IntlTimeZone Object
(
[valid] => 1
[id] => GMT+03:33
[rawOffset] => 12780000
[currentOffset] => 12780000
)
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::getType — Get the calendar type
Object oriented style
Procedural style
A string describing the type of this calendar. This is one of the valid values for
the calendar keyword value 'calendar'.
calThe IntlCalendar resource.
A string representing the calendar type, such as
'gregorian', 'islamic', etc.
Example #1 IntlCalendar::getType()
<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'en_US');
$cal = IntlCalendar::createInstance(NULL, '@calendar=ethiopic-amete-alem');
var_dump($cal->getType());
$cal = new IntlGregorianCalendar();
var_dump($cal->getType());
The above example will output:
string(19) "ethiopic-amete-alem" string(9) "gregorian"
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::getWeekendTransition — Get time of the day at which weekend begins or ends
Object oriented style
$dayOfWeek
) : intProcedural style
Returns the number of milliseconds after midnight at which the weekend begins or ends.
This is only applicable for days of the week for which
IntlCalendar::getDayOfWeekType() returns either
IntlCalendar::DOW_TYPE_WEEKEND_OFFSET or
IntlCalendar::DOW_TYPE_WEEKEND_CEASE. Calling this
function for other days of the week is an error condition.
This function requires ICU 4.4 or later.
calThe IntlCalendar resource.
dayOfWeek
One of the constants IntlCalendar::DOW_SUNDAY,
IntlCalendar::DOW_MONDAY, …,
IntlCalendar::DOW_SATURDAY.
The number of milliseconds into the day at which the weekend begins or
ends or FALSE on failure.
See example on IntlCalendar::getDayOfWeekType().
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::inDaylightTime — Whether the objectʼs time is in Daylight Savings Time
Object oriented style
Procedural style
Whether, for the instant represented by this object and for this objectʼs timezone, daylight saving time is in place.
calThe IntlCalendar resource.
Returns TRUE if the date is in Daylight Savings Time, FALSE otherwise.
The value FALSE may also be returned on failure, for instance after
specifying invalid field values on non-lenient mode; use exceptions or query
intl_get_error_code() to disambiguate.
Example #1 IntlCalendar::inDaylightTime()
<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'pt_PT');
$cal = new IntlGregorianCalendar(2013, 6 /* July */, 1, 4, 56, 31);
var_dump($cal->inDaylightTime()); // true
$cal->set(IntlCalendar::FIELD_MONTH, 11 /* December */);
var_dump($cal->inDaylightTime()); // false
//DST end transition on 2013-10-27 at 0200 (wall time back 1 hour)
$cal = new IntlGregorianCalendar(2013, 9 /* October */, 27, 1, 30, 0);
var_dump($cal->inDaylightTime()); // false (default WALLTIME_LAST)
$cal->setRepeatedWallTimeOption(IntlCalendar::WALLTIME_FIRST);
$cal->set(IntlCalendar::FIELD_HOUR_OF_DAY, 1); // force time recalculation
var_dump($cal->inDaylightTime()); // true
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::isEquivalentTo — Whether another calendar is equal but for a different time
Object oriented style
Procedural style
Returns whether this and the given object are equivalent for all purposes except as to the time they have set. The locales do not have to match, as long as no change in behavior results from such mismatch. This includes the timezone, whether the lenient mode is set, the repeated and skipped wall time settings, the days of the week when the weekend starts and ceases and the times where such transitions occur. It may also include other calendar specific settings, such as the Gregorian/Julian transition instant.
calThe IntlCalendar resource.
otherThe other calendar against which the comparison is to be made.
Assuming there are no argument errors, returns TRUE if the calendars are
equivalent except possibly for their set time.
Example #1 IntlCalendar::isEquivalentTo()
<?php
$cal1 = IntlCalendar::createInstance('Europe/Lisbon', 'pt_PT');
$cal2 = IntlCalendar::createInstance('Europe/Lisbon', 'es_ES');
$cal2->clear();
var_dump($cal1->isEquivalentTo($cal2)); // true
$cal3 = IntlCalendar::createInstance('Europe/Lisbon', 'en_US');
var_dump($cal1->isEquivalentTo($cal3)); // false
var_dump($cal1->getFirstDayOfWeek(), // 2 (Monday)
$cal3->getFirstDayOfWeek()); // 1 (Sunday)
The above example will output:
bool(true) bool(false) int(2) int(1)
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::isLenient — Whether date/time interpretation is in lenient mode
Object oriented style
Procedural style
Returns whether the current date/time interpretations is lenient (the default). If that is case, some out of range values for fields will be accepted instead of raising an error.
calThe IntlCalendar resource.
A bool representing whether the calendar is set to lenient mode.
Example #1 IntlCalendar::isLenient()
<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'pt_PT');
ini_set('intl.use_exceptions', '1');
$cal = new IntlGregorianCalendar(2013, 6 /* July */, 1);
var_dump(IntlDateFormatter::formatObject($cal), // 01/07/2013, 00:00:00
$cal->isLenient()); // true
$cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 33);
var_dump(IntlDateFormatter::formatObject($cal)); // 02/08/2013, 00:00:00
$cal->setLenient(false);
var_dump($cal->isLenient()); // false
$cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 33);
var_dump(IntlDateFormatter::formatObject($cal)); // error
The above example will output:
string(20) "01/07/2013, 00:00:00"
bool(true)
string(20) "02/08/2013, 00:00:00"
bool(false)
Fatal error: Uncaught exception 'IntlException' with message 'datefmt_format_object: error obtaining instant from IntlCalendar' in /home/foobar/example.php:16
Stack trace:
#0 /home/foobar/example.php(16): IntlDateFormatter::formatObject(Object(IntlGregorianCalendar))
#1 {main}
thrown in /home/foobar/example.php on line 16
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::isSet — Whether a field is set
Object oriented style
$field
) : boolProcedural style
Returns whether a field is set (as opposed to clear). Set fields take priority over unset fields and their default values when the date/time is being calculated. Fields set later take priority over fields set earlier.
calThe IntlCalendar resource.
field
One of the IntlCalendar date/time field constants. These are integer
values between 0 and
IntlCalendar::FIELD_COUNT.
Assuming there are no argument errors, returns TRUE if the field is set.
See the example on IntlCalendar::clear().
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::isWeekend — Whether a certain date/time is in the weekend
Object oriented style
$date = NULL
] ) : boolProcedural style
Returns whether either the obejctʼs current time or the provided timestamp occur during a weekend in this objectʼs calendar system.
This function requires ICU 4.4 or later.
calThe IntlCalendar resource.
date
An optional timestamp representing the number of milliseconds since the
epoch, excluding leap seconds. If NULL, this objectʼs current time is
used instead.
A bool indicating whether the given or this objectʼs time occurs in a weekend.
The value FALSE may also be returned on failure, for instance after giving
a date out of bounds on non-lenient mode; use exceptions or query
intl_get_error_code() to disambiguate.
Example #1 IntlCalendar::isWeekend()
<?php
ini_set('date.timezone', 'Europe/Lisbon');
$cal = new IntlGregorianCalendar(NULL, 'en_US');
$cal->set(2013, 6 /* July */, 7); // a Sunday
var_dump($cal->isWeekend()); // true
var_dump($cal->isWeekend(strtotime('2013-07-01 00:00:00'))); // false, Monday
$cal = new IntlGregorianCalendar(NULL, 'ar_SA');
$cal->set(2013, 6 /* July */, 7); // a Sunday
var_dump($cal->isWeekend()); // false, Sunday not in weekend in this calendar
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::roll — Add value to field without carrying into more significant fields
Object oriented style
Procedural style
Adds a (signed) amount to a field. The difference with respect to IntlCalendar::add() is that when the field value overflows, it does not carry into more significant fields.
calThe IntlCalendar resource.
field
One of the IntlCalendar date/time field constants. These are integer
values between 0 and
IntlCalendar::FIELD_COUNT.
amountOrUpOrDown
The (signed) amount to add to the field, TRUE for rolling up (adding
1), or FALSE for rolling down (subtracting
1).
Returns TRUE on success or FALSE on failure.
Example #1 IntlCalendar::roll()
<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'pt_PT');
$cal = new IntlGregorianCalendar(2013, 5 /* June */, 30);
$cal->add(IntlCalendar::FIELD_DAY_OF_MONTH, 1);
var_dump(IntlDateFormatter::formatObject($cal)); // "01/07/2013, 00:00:00"
$cal->set(2013, 5 /* June */, 30);
$cal->roll(IntlCalendar::FIELD_DAY_OF_MONTH, true); // roll up, same as rolling +1
var_dump(IntlDateFormatter::formatObject($cal)); // "01/06/2013, 00:00:00"
The above example will output:
string(20) "01/07/2013, 00:00:00" string(20) "01/06/2013, 00:00:00"
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::set — Set a time field or several common fields at once
Object oriented style
$field
, int $value
) : bool$year
, int $month
[, int $dayOfMonth = NULL
[, int $hour = NULL
[, int $minute = NULL
[, int $second = NULL
]]]] ) : boolProcedural style
$cal
, int $year
, int $month
[, int $dayOfMonth = NULL
[, int $hour = NULL
[, int $minute = NULL
[, int $second = NULL
]]]] ) : boolSets either a specific field to the given value, or sets at once several common fields. The range of values that are accepted depend on whether the calendar is using the lenient mode.
For fields that conflict, the fields that are set later have priority.
This method cannot be called with exactly four arguments.
calThe IntlCalendar resource.
field
One of the IntlCalendar date/time field constants. These are integer
values between 0 and
IntlCalendar::FIELD_COUNT.
valueThe new value of the given field.
year
The new value for IntlCalendar::FIELD_YEAR.
month
The new value for IntlCalendar::FIELD_MONTH.
dayOfMonth
The new value for IntlCalendar::FIELD_DAY_OF_MONTH.
The month sequence is zero-based, i.e., January is represented by 0,
February by 1, …, December is 11 and Undecember (if the calendar has
it) is 12.
hour
The new value for IntlCalendar::FIELD_HOUR_OF_DAY.
minute
The new value for IntlCalendar::FIELD_MINUTE.
second
The new value for IntlCalendar::FIELD_SECOND.
Returns TRUE on success and FALSE on failure.
Example #1 IntlCalendar::set()
<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'pt_PT');
//Calls made later have priority
$cal = new IntlGregorianCalendar(2013, 6 /* July */, 1);
$cal->set(IntlCalendar::FIELD_YEAR, 2012);
$cal->set(IntlCalendar::FIELD_EXTENDED_YEAR, 2011);
var_dump(IntlDateFormatter::formatObject($cal));
$cal = new IntlGregorianCalendar(2013, 6 /* July */, 1);
$cal->set(IntlCalendar::FIELD_YEAR, 2012);
$cal->set(IntlCalendar::FIELD_EXTENDED_YEAR, 2011);
//the time has not been recalculated yet. If we clear the extended year,
//the year set before will be used
$cal->clear(IntlCalendar::FIELD_EXTENDED_YEAR);
var_dump(IntlDateFormatter::formatObject($cal));
The above example will output:
string(20) "01/07/2011, 00:00:00" string(20) "01/07/2012, 00:00:00"
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::setFirstDayOfWeek — Set the day on which the week is deemed to start
Object oriented style
$dayOfWeek
) : boolProcedural style
Defines the day of week deemed to start the week. This affects the behavior
of fields that depend on the concept of week start and end such as
IntlCalendar::FIELD_WEEK_OF_YEAR and
IntlCalendar::FIELD_YEAR_WOY.
calThe IntlCalendar resource.
dayOfWeek
One of the constants IntlCalendar::DOW_SUNDAY,
IntlCalendar::DOW_MONDAY, …,
IntlCalendar::DOW_SATURDAY.
Returns TRUE on success. Failure can only happen due to invalid parameters.
Example #1 IntlCalendar::setFirstDayOfWeek()
<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'es_ES');
$cal = IntlCalendar::createInstance();
$cal->set(2013, 5 /* June */, 30); // A Sunday
var_dump($cal->getFirstDayOfWeek()); // 2 (Monday)
echo IntlDateFormatter::formatObject($cal, <<<EOD
'local day of week: 'cc'
week of month : 'W'
week of year : 'ww
EOD
), "\n";
$cal->setFirstDayOfWeek(IntlCalendar::DOW_SUNDAY);
echo IntlDateFormatter::formatObject($cal, <<<EOD
'local day of week: 'cc'
week of month : 'W'
week of year : 'ww
EOD
), "\n";
The above example will output:
int(2) local day of week: 7 week of month : 4 week of year : 26 local day of week: 1 week of month : 5 week of year : 27
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::setLenient — Set whether date/time interpretation is to be lenient
Object oriented style
$isLenient
) : boolProcedural style
Defines whether the calendar is ‘lenient mode’. In such a mode, some of out-of-bounds values for some fields are accepted, the behavior being similar to that of IntlCalendar::add() (i.e., the value wraps around, carrying into more significant fields each time). If the lenient mode is off, then such values will generate an error.
calThe IntlCalendar resource.
isLenient
Use TRUE to activate the lenient mode; FALSE otherwise.
Returns TRUE on success. Failure can only happen due to invalid parameters.
See the example in IntlCalendar::isLenient().
(PHP 5 >= 5.5.1, PHP 7)
IntlCalendar::setMinimalDaysInFirstWeek — Set minimal number of days the first week in a year or month can have
Object oriented style
$minimalDays
) : boolProcedural style
Sets the smallest number of days the first week of a year or month must have in the new year or month. For instance, in the Gregorian calendar, if this value is 1, then the first week of the year will necessarily include January 1st, while if this value is 7, then the week with January 1st will be the first week of the year only if the day of the week for January 1st matches the day of the week returned by IntlCalendar::getFirstDayOfWeek(); otherwise it will be the previous yearʼs last week.
calThe IntlCalendar resource.
minimalDaysThe number of minimal days to set.
TRUE on success, FALSE on failure.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::setRepeatedWallTimeOption — Set behavior for handling repeating wall times at negative timezone offset transitions
Object oriented style
$wallTimeOption
) : boolProcedural style
Sets the current strategy for dealing with wall times that are repeated
whenever the clock is set back during dailight saving time end transitions.
The default value is IntlCalendar::WALLTIME_LAST (take
the post-DST instant). The other possible value is
IntlCalendar::WALLTIME_FIRST (take the instant that
occurs during DST).
This function requires ICU 4.9 or later.
calThe IntlCalendar resource.
wallTimeOption
One of the constants IntlCalendar::WALLTIME_FIRST or
IntlCalendar::WALLTIME_LAST.
Returns TRUE on success. Failure can only happen due to invalid parameters.
See the example on IntlCalendar::getRepeatedWallTimeOption().
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::setSkippedWallTimeOption — Set behavior for handling skipped wall times at positive timezone offset transitions
Object oriented style
$wallTimeOption
) : boolProcedural style
Sets the current strategy for dealing with wall times that are skipped
whenever the clock is forwarded during dailight saving time start transitions.
The default value is IntlCalendar::WALLTIME_LAST (take
it as being the same instant as the one when the wall time is one hour
more). Alternative values are
IntlCalendar::WALLTIME_FIRST (same instant as the one
with a wall time of one hour less) and
IntlCalendar::WALLTIME_NEXT_VALID (same instant as
when DST begins).
This affects only the instant represented by the calendar (as reported by IntlCalendar::getTime()), the field values will not be rewritten accordingly.
The calendar must be lenient for this option to have any effect, otherwise attempting to set a non-existing time will cause an error.
This function requires ICU 4.9 or later.
calThe IntlCalendar resource.
wallTimeOption
One of the constants IntlCalendar::WALLTIME_FIRST,
IntlCalendar::WALLTIME_LAST or
IntlCalendar::WALLTIME_NEXT_VALID.
Returns TRUE on success. Failure can only happen due to invalid parameters.
See the example on IntlCalendar::getSkippedWallTimeOption().
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::setTime — Set the calendar time in milliseconds since the epoch
Object oriented style
$date
) : boolProcedural style
Sets the instant represented by this object. The instant is represented by a float whose value should be an integer number of milliseconds since the epoch (1 Jan 1970 00:00:00.000 UTC), ignoring leap seconds. All the field values will be recalculated accordingly.
calThe IntlCalendar resource.
dateAn instant represented by the number of number of milliseconds between such instant and the epoch, ignoring leap seconds.
Returns TRUE on success and FALSE on failure.
Example #1 IntlCalendar::setTime()
<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'fr_FR');
$cal = new IntlGregorianCalendar(2013, 5 /* May */, 1, 12, 0, 0);
echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL), "\n";
/* In Europe/Lisbon, on 2013-10-27 at 0200, the clock goes back one hour and
the timezone from UTC+01 to UTC+00 */
$cal->setTime(strtotime('2013-10-27 00:30:00 UTC') * 1000.);
echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL), "\n";
$cal->setTime(strtotime('2013-10-27 01:30:00 UTC') * 1000.);
echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL), "\n";
The above example will output:
samedi 1 juin 2013 12:00:00 heure avancée d’Europe de l’Ouest dimanche 27 octobre 2013 01:30:00 heure avancée d’Europe de l’Ouest dimanche 27 octobre 2013 01:30:00 heure normale d’Europe de l’Ouest
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlCalendar::setTimeZone — Set the timezone used by this calendar
Object oriented style
Procedural style
Defines a new timezone for this calendar. The time represented by the object is preserved to the detriment of the field values.
calThe IntlCalendar resource.
timeZoneThe new timezone to be used by this calendar. It can be specified in the following ways:
NULL, in which case the default timezone will be used, as specified in
the ini setting date.timezone or
through the function date_default_timezone_set() and as
returned by date_default_timezone_get().
An IntlTimeZone, which will be used directly.
A DateTimeZone. Its identifier will be extracted and an ICU timezone object will be created; the timezone will be backed by ICUʼs database, not PHPʼs.
A string, which should be a valid ICU timezone identifier.
See IntlTimeZone::createTimeZoneIDEnumeration(). Raw
offsets such as "GMT+08:30" are also accepted.
Returns TRUE on success and FALSE on failure.
Example #1 IntlCalendar::setTimeZone()
<?php
ini_set('date.timezone', 'Europe/Lisbon');
ini_set('intl.default_locale', 'es_ES');
$cal = new IntlGregorianCalendar(2013, 5 /* May */, 1, 12, 0, 0);
echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL), "\n";
echo "(instant {$cal->getTime()})\n";
$cal->setTimeZone(IntlTimeZone::getGMT());
echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL), "\n";
echo "(instant {$cal->getTime()})\n";
$cal->setTimeZone('GMT+03:33');
echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL), "\n";
echo "(instant {$cal->getTime()})\n";
The above example will output:
sábado, 1 de junio de 2013 12:00:00 Hora de verano de Europa occidental (instant 1370084400000) sábado, 1 de junio de 2013 11:00:00 GMT (instant 1370084400000) sábado, 1 de junio de 2013 14:33:00 GMT+03:33 (instant 1370084400000)
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a2)
IntlCalendar::toDateTime — Convert an IntlCalendar into a DateTime object
Object oriented style
Procedural style
Create a DateTime object that represents the same instant (up to second precision, with a rounding error of less than 1 second) and has an analog timezone to this object (the difference being DateTimeʼs timezone will be backed by PHPʼs timezone while IntlCalendarʼs timezone is backed by ICUʼs).
calThe IntlCalendar resource.
A DateTime object with the same timezone as this
object (though using PHPʼs database instead of ICUʼs) and the same time,
except for the smaller precision (second precision instead of millisecond).
Returns FALSE on failure.
Example #1 IntlCalendar::toDateTime()
<?php
ini_set('date.timezone', 'UTC');
ini_set('intl.default_locale', 'pt_PT');
$cal = IntlCalendar::createInstance('Europe/Lisbon'); //current time
$dt = $cal->toDateTime();
print_r($dt);
The above example will output:
DateTime Object
(
[date] => 2013-07-02 00:29:13
[timezone_type] => 3
[timezone] => Europe/Lisbon
)
(PHP 5 >= 5.5.0, PHP 7)
$timeZone = NULL
[, string $locale = ""
]] ) : IntlCalendar$key
, string $locale
, bool $commonlyUsed
) : Iterator$key
, string $locale
, bool $commonlyUsed
) : Iterator$year
, int $month
[, int $dayOfMonth = NULL
[, int $hour = NULL
[, int $minute = NULL
[, int $second = NULL
]]]] ) : bool$cal
, int $year
, int $month
[, int $dayOfMonth = NULL
[, int $hour = NULL
[, int $minute = NULL
[, int $second = NULL
]]]] ) : bool(PHP 5 >= 5.5.0, PHP 7)
IntlGregorianCalendar::__construct — Create the Gregorian Calendar class
$timeZoneOrYear
, int $localeOrMonth
, int $dayOfMonth
)$timeZoneOrYear
, int $localeOrMonth
, int $dayOfMonth
, int $hour
, int $minute
[, int $second
] )
This function is currently not documented; only its argument list is available.
tz
locale
timeZoneOrYear
localeOrMonth
dayOfMonth
hour
minute
second
(PHP 5 >= 5.5.0, PHP 7)
IntlGregorianCalendar::getGregorianChange — Get the Gregorian Calendar change date
This function is currently not documented; only its argument list is available.
This function has no parameters.
Returns the change date or FALSE on failure.
(PHP 5 >= 5.5.0, PHP 7)
IntlGregorianCalendar::isLeapYear — Determine if the given year is a leap year
$year
) : bool
This function is currently not documented; only its argument list is available.
year
Returns TRUE for leap years, FALSE otherwise and on failure.
(PHP 5 >= 5.5.0, PHP 7)
IntlGregorianCalendar::setGregorianChange — Set the Gregorian Calendar the change date
$date
) : bool
This function is currently not documented; only its argument list is available.
date
Returns TRUE on success or FALSE on failure.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
$zoneType
[, string $region
[, int $rawOffset
]] ) : IntlIteratorIntlTimeZone::DISPLAY_SHORTIntlTimeZone::DISPLAY_LONG(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlTimeZone::countEquivalentIDs — Get the number of IDs in the equivalency group that includes the given ID
$zoneId
) : int
This function is currently not documented; only its argument list is available.
zoneId
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlTimeZone::createDefault — Create a new copy of the default timezone for this host
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlTimeZone::createEnumeration — Get an enumeration over time zone IDs associated with the given country or offset
This function is currently not documented; only its argument list is available.
countryOrRawOffset
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlTimeZone::createTimeZone — Create a timezone object for the given ID
This function is currently not documented; only its argument list is available.
zoneId
(PHP 5 >= 5.5.0, PHP 7)
IntlTimeZone::createTimeZoneIDEnumeration — Get an enumeration over system time zone IDs with the given filter conditions
$zoneType
[, string $region
[, int $rawOffset
]] ) : IntlIterator
This function is currently not documented; only its argument list is available.
zoneType
region
rawOffset
Returns IntlIterator or FALSE on failure.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlTimeZone::fromDateTimeZone — Create a timezone object from DateTimeZone
This function is currently not documented; only its argument list is available.
zoneId
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlTimeZone::getCanonicalID — Get the canonical system timezone ID or the normalized custom time zone ID for the given time zone ID
$zoneId
[, bool &$isSystemID
] ) : string
This function is currently not documented; only its argument list is available.
zoneId
isSystemID
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlTimeZone::getDisplayName — Get a name of this time zone suitable for presentation to the user
$isDaylight
[, int $style
[, string $locale
]]] ) : string
This function is currently not documented; only its argument list is available.
isDaylight
style
locale
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlTimeZone::getDSTSavings — Get the amount of time to be added to local standard time to get local wall clock time
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlTimeZone::getEquivalentID — Get an ID in the equivalency group that includes the given ID
$zoneId
, int $index
) : string
This function is currently not documented; only its argument list is available.
zoneId
index
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlTimeZone::getErrorCode -- intltz_get_error_code — Get last error code on the object
Object oriented style (method):
Procedural style:
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlTimeZone::getErrorMessage -- intltz_get_error_message — Get last error message on the object
Object oriented style (method):
Procedural style:
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlTimeZone::getGMT — Create GMT (UTC) timezone
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlTimeZone::getID — Get timezone ID
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 7 >= 7.1.0)
IntlTimeZone::getIDForWindowsID — Translate a Windows timezone into a system timezone
$timezone
[, string $region
] ) : stringTranslates a Windows timezone (e.g. "Pacific Standard Time") into a system timezone (e.g. "America/Los_Angeles").
Note: This function requires ICU version ≥ 52.
This function is currently not documented; only its argument list is available.
timezone
region
Returns the system timezone or FALSE on failure.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlTimeZone::getOffset — Get the time zone raw and GMT offset for the given moment in time
$date
, bool $local
, int &$rawOffset
, int &$dstOffset
) : int
This function is currently not documented; only its argument list is available.
date
local
rawOffset
dstOffset
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlTimeZone::getRawOffset — Get the raw GMT offset (before taking daylight savings time into account
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7)
IntlTimeZone::getRegion — Get the region code associated with the given system time zone ID
$zoneId
) : string
This function is currently not documented; only its argument list is available.
zoneId
Return region or FALSE on failure.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlTimeZone::getTZDataVersion — Get the timezone data version currently used by ICU
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7)
IntlTimeZone::getUnknown — Get the "unknown" time zone
This function is currently not documented; only its argument list is available.
This function has no parameters.
Returns IntlTimeZone or NULL on failure.
(PHP 7 >= 7.1.0)
IntlTimeZone::getWindowsID — Translate a system timezone into a Windows timezone
$timezone
) : stringTranslates a system timezone (e.g. "America/Los_Angeles") into a Windows timezone (e.g. "Pacific Standard Time").
Note: This function requires ICU version ≥ 52.
This function is currently not documented; only its argument list is available.
timezone
Returns the Windows timezone or FALSE on failure.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlTimeZone::hasSameRules — Check if this zone has the same rules and offset as another zone
This function is currently not documented; only its argument list is available.
otherTimeZone
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlTimeZone::toDateTimeZone — Convert to DateTimeZone object
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
IntlTimeZone::useDaylightTime — Check if this time zone uses daylight savings time
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Date Formatter is a concrete class that enables locale-dependent formatting/parsing of dates using pattern strings and/or canned patterns.
This class represents the ICU date formatting functionality. It allows users to display dates in a localized format or to parse strings into PHP date values using pattern strings and/or canned patterns.
$locale
, int $datetype
, int $timetype
[, mixed $timezone = NULL
[, mixed $calendar = NULL
[, string $pattern = ""
]]] )$locale
, int $datetype
, int $timetype
[, mixed $timezone = NULL
[, mixed $calendar = NULL
[, string $pattern = ""
]]] ) : IntlDateFormatter$object
[, mixed $format = NULL
[, string $locale = NULL
]] ) : stringThese constants are used to specify different formats in the constructor for DateType and TimeType.
IntlDateFormatter::NONE
(integer)
IntlDateFormatter::FULL
(integer)
IntlDateFormatter::LONG
(integer)
IntlDateFormatter::MEDIUM
(integer)
IntlDateFormatter::SHORT
(integer)
The following int constants are used to specify the calendar. These calendars are all based directly on the Gregorian calendar. Non-Gregorian calendars need to be specified in locale. Examples might include locale="hi@calendar=BUDDHIST".
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
IntlDateFormatter::create -- datefmt_create -- IntlDateFormatter::__construct — Create a date formatter
Object oriented style
$locale
, int $datetype
, int $timetype
[, mixed $timezone = NULL
[, mixed $calendar = NULL
[, string $pattern = ""
]]] ) : IntlDateFormatterObject oriented style (constructor)
$locale
, int $datetype
, int $timetype
[, mixed $timezone = NULL
[, mixed $calendar = NULL
[, string $pattern = ""
]]] )Procedural style
$locale
, int $datetype
, int $timetype
[, mixed $timezone = NULL
[, mixed $calendar = NULL
[, string $pattern = ""
]]] ) : IntlDateFormatterCreate a date formatter.
locale
Locale to use when formatting or parsing or NULL to use the value
specified in the ini setting intl.default_locale.
datetype
Date type to use (none, short,
medium, long,
full). This is one of the IntlDateFormatter
constants. It can also be NULL, in which case ICUʼs default
date type will be used.
timetype
Time type to use (none, short,
medium, long,
full). This is one of the IntlDateFormatter
constants. It can also be NULL, in which case ICUʼs default
time type will be used.
timezone
Time zone ID. The default (and the one used if NULL is given) is the
one returned by date_default_timezone_get() or, if
applicable, that of the IntlCalendar object passed
for the calendar parameter. This ID must be a
valid identifier on ICUʼs database or an ID representing an
explicit offset, such as GMT-05:30.
This can also be an IntlTimeZone or a DateTimeZone object.
calendar
Calendar to use for formatting or parsing. The default value is NULL,
which corresponds to IntlDateFormatter::GREGORIAN.
This can either be one of the
IntlDateFormatter
calendar constants or an IntlCalendar. Any
IntlCalendar object passed will be clone; it will
not be changed by the IntlDateFormatter. This will
determine the calendar type used (gregorian, islamic, persian, etc.) and,
if NULL is given for the timezone parameter,
also the timezone used.
patternOptional pattern to use when formatting or parsing. Possible patterns are documented at » http://userguide.icu-project.org/formatparse/datetime.
The created IntlDateFormatter or FALSE in case of
failure.
| Version | Description |
|---|---|
| 5.5.0/PECL 3.0.0 |
An IntlCalendar object is allowed for
Objects of type IntlTimeZone and
DateTimeZone are allowed for
Invalid timezone identifiers (including empty strings) are no longer
allowed for
If |
Example #1 datefmt_create() example
<?php
$fmt = datefmt_create( "en_US" ,IntlDateFormatter::FULL, IntlDateFormatter::FULL,
'America/Los_Angeles', IntlDateFormatter::GREGORIAN );
echo "First Formatted output is ".datefmt_format( $fmt , 0);
$fmt = datefmt_create( "de-DE" ,IntlDateFormatter::FULL, IntlDateFormatter::FULL,
'America/Los_Angeles',IntlDateFormatter::GREGORIAN );
echo "Second Formatted output is ".datefmt_format( $fmt , 0);
$fmt = datefmt_create( "en_US" ,IntlDateFormatter::FULL, IntlDateFormatter::FULL,
'America/Los_Angeles',IntlDateFormatter::GREGORIAN ,"MM/dd/yyyy");
echo "First Formatted output with pattern is ".datefmt_format( $fmt , 0);
$fmt = datefmt_create( "de-DE" ,IntlDateFormatter::FULL, IntlDateFormatter::FULL,
'America/Los_Angeles',IntlDateFormatter::GREGORIAN ,"MM/dd/yyyy");
echo "Second Formatted output with pattern is ".datefmt_format( $fmt , 0);
?>
Example #2 OO example
<?php
$fmt = new IntlDateFormatter( "en_US" ,IntlDateFormatter::FULL, IntlDateFormatter::FULL,
'America/Los_Angeles',IntlDateFormatter::GREGORIAN );
echo "First Formatted output is ".$fmt->format(0);
$fmt = new IntlDateFormatter( "de-DE" ,IntlDateFormatter::FULL, IntlDateFormatter::FULL,
'America/Los_Angeles',IntlDateFormatter::GREGORIAN );
echo "Second Formatted output is ".$fmt->format(0);
$fmt = new IntlDateFormatter( "en_US" ,IntlDateFormatter::FULL, IntlDateFormatter::FULL,
'America/Los_Angeles',IntlDateFormatter::GREGORIAN ,"MM/dd/yyyy");
echo "First Formatted output with pattern is ".$fmt->format(0);
$fmt = new IntlDateFormatter( "de-DE" ,IntlDateFormatter::FULL, IntlDateFormatter::FULL,
'America/Los_Angeles',IntlDateFormatter::GREGORIAN , "MM/dd/yyyy");
echo "Second Formatted output with pattern is ".$fmt->format(0);
?>
The above example will output:
First Formatted output is Wednesday, December 31, 1969 4:00:00 PM PT
Second Formatted output is Mittwoch, 31. Dezember 1969 16:00 Uhr GMT-08:00
First Formatted output with pattern is 12/31/1969
Second Formatted output with pattern is 12/31/1969
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
IntlDateFormatter::format -- datefmt_format — Format the date/time value as a string
Object oriented style
Procedural style
Formats the time value as a string.
fmtThe date formatter resource.
valueValue to format. This may be a DateTimeInterface object, an IntlCalendar object, a numeric type representing a (possibly fractional) number of seconds since epoch or an array in the format output by localtime().
If a DateTime or an IntlCalendar object is passed, its timezone is not considered. The object will be formatted using the formaterʼs configured timezone. If one wants to use the timezone of the object to be formatted, IntlDateFormatter::setTimeZone() must be called before with the objectʼs timezone. Alternatively, the static function IntlDateFormatter::formatObject() may be used instead.
The formatted string or, if an error occurred, FALSE.
| Version | Description |
|---|---|
| 7.1.5 |
Support for providing general DateTimeInterface objects to the
value parameter was added. Formerly, only proper
DateTime objects were supported.
|
| 5.5.0/PECL 3.0.0 |
Support for providing IntlCalendar objects to the
value parameter was added.
|
| 5.3.4 |
Support for providing DateTime objects to the
value parameter was added.
|
Example #1 datefmt_format() example
<?php
$fmt = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'First Formatted output is ' . datefmt_format($fmt, 0);
$fmt = datefmt_create(
'de-DE',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'Second Formatted output is ' . datefmt_format($fmt, 0);
$fmt = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN,
'MM/dd/yyyy'
);
echo 'First Formatted output with pattern is ' . datefmt_format($fmt, 0);
$fmt = datefmt_create(
'de-DE',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN,
'MM/dd/yyyy'
);
echo "Second Formatted output with pattern is " . datefmt_format($fmt, 0);
?>
Example #2 OO example
<?php
$fmt = new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'First Formatted output is ' . $fmt->format(0);
$fmt = new IntlDateFormatter(
'de-DE',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'Second Formatted output is ' . $fmt->format(0);
$fmt = new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN,
'MM/dd/yyyy'
);
echo 'First Formatted output with pattern is ' . $fmt->format(0);
$fmt = new IntlDateFormatter(
'de-DE',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN,
'MM/dd/yyyy'
);
echo 'Second Formatted output with pattern is ' . $fmt->format(0);
?>
The above example will output:
First Formatted output is Wednesday, December 31, 1969 4:00:00 PM PT Second Formatted output is Mittwoch, 31. Dezember 1969 16:00 Uhr GMT-08:00 First Formatted output with pattern is 12/31/1969 Second Formatted output with pattern is 12/31/1969
Example #3 With IntlCalendar object
<?php
$tz = reset(iterator_to_array(IntlTimeZone::createEnumeration('FR')));
$formatter = IntlDateFormatter::create(
'fr_FR',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
$tz,
IntlDateFormatter::GREGORIAN
);
$cal = IntlCalendar::createInstance($tz, '@calendar=islamic-civil');
$cal->set(IntlCalendar::FIELD_MONTH, 8); //9th month, Ramadan
$cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 1); //1st day
$cal->clear(IntlCalendar::FIELD_HOUR_OF_DAY);
$cal->clear(IntlCalendar::FIELD_MINUTE);
$cal->clear(IntlCalendar::FIELD_SECOND);
$cal->clear(IntlCalendar::FIELD_MILLISECOND);
echo "In this islamic year, Ramadan started/will start on:\n\t",
$formatter->format($cal), "\n";
//Itʼs the formatterʼs timezone that is used:
$formatter->setTimeZone('Asia/Tokyo');
echo "After changing timezone:\n\t",
$formatter->format($cal), "\n";
The above example will output:
In this islamic year, Ramadan started/will start on:
mardi 9 juillet 2013 19:00:00 heure avancée d’Europe centrale
After changing timezone:
mercredi 10 juillet 2013 02:00:00 heure normale du Japon
(PHP 5 >= 5.5.0, PHP 7, PECL intl >= 3.0.0)
IntlDateFormatter::formatObject -- datefmt_format_object — Formats an object
Object oriented style
$object
[, mixed $format = NULL
[, string $locale = NULL
]] ) : stringProcedural style
$object
[, mixed $format = NULL
[, string $locale = NULL
]] ) : stringThis function allows formatting an IntlCalendar or DateTime object without first explicitly creating a IntlDateFormatter object.
The temporary IntlDateFormatter that will be created will take the timezone from the passed in object. The timezone database bundled with PHP will not be used – ICU's will be used instead. The timezone identifier used in DateTime objects must therefore also exist in ICU's database.
objectAn object of type IntlCalendar or DateTime. The timezone information in the object will be used.
format
How to format the date/time. This can either be an array with
two elements (first the date style, then the time style, these being one
of the constants IntlDateFormatter::NONE,
IntlDateFormatter::SHORT,
IntlDateFormatter::MEDIUM,
IntlDateFormatter::LONG,
IntlDateFormatter::FULL), an integer with
the value of one of these constants (in which case it will be used both
for the time and the date) or a string with the format
described in » the ICU
documentation. If NULL, the default style will be used.
locale
The locale to use, or NULL to use the default one.
A string with result or FALSE on failure.
Example #1 IntlDateFormatter::formatObject() examples
<?php
/* default timezone is irrelevant; timezone taken from the object */
ini_set('date.timezone', 'UTC');
/* default locale is taken from this ini setting */
ini_set('intl.default_locale', 'fr_FR');
$cal = IntlCalendar::fromDateTime("2013-06-06 17:05:06 Europe/Dublin");
echo "default:\n\t",
IntlDateFormatter::formatObject($cal),
"\n";
echo "long \$format (full):\n\t",
IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL),
"\n";
echo "array \$format (none, full):\n\t",
IntlDateFormatter::formatObject($cal, array(
IntlDateFormatter::NONE,
IntlDateFormatter::FULL)),
"\n";
echo "string \$format (d 'of' MMMM y):\n\t",
IntlDateFormatter::formatObject($cal, "d 'of' MMMM y", 'en_US'),
"\n";
echo "with DateTime:\n\t",
IntlDateFormatter::formatObject(
new DateTime("2013-09-09 09:09:09 Europe/Madrid"),
IntlDateFormatter::FULL,
'es_ES'),
"\n";
The above example will output:
default:
6 juin 2013 17:05:06
long $format (full):
jeudi 6 juin 2013 17:05:06 heure d’été irlandaise
array $format (none, full):
17:05:06 heure d’été irlandaise
string $format (d 'of' MMMM y):
6 of June 2013
with DateTime:
lunes, 9 de septiembre de 2013 09:09:09 Hora de verano de Europa central
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
IntlDateFormatter::getCalendar -- datefmt_get_calendar — Get the calendar type used for the IntlDateFormatter
Object oriented style
Procedural style
fmtThe formatter resource
The calendar
type being used by the formatter. Either
IntlDateFormatter::TRADITIONAL or
IntlDateFormatter::GREGORIAN.
Example #1 datefmt_get_calendar() example
<?php
$fmt = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'calendar of the formatter is : ' . datefmt_get_calendar($fmt);
datefmt_set_calendar($fmt, IntlDateFormatter::TRADITIONAL);
echo 'Now calendar of the formatter is : ' . datefmt_get_calendar($fmt);
?>
Example #2 OO example
<?php
$fmt = new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'calendar of the formatter is : ' . $fmt->getCalendar();
$fmt->setCalendar(IntlDateFormatter::TRADITIONAL);
echo 'Now calendar of the formatter is : ' . $fmt->getCalendar();
?>
The above example will output:
calendar of the formatter is : 1 Now calendar of the formatter is : 0
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
IntlDateFormatter::getDateType -- datefmt_get_datetype — Get the datetype used for the IntlDateFormatter
Object oriented style
Procedural style
Returns date type used by the formatter.
fmtThe formatter resource.
The current date type value of the formatter.
Example #1 datefmt_get_datetype() example
<?php
$fmt = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'datetype of the formatter is : ' . datefmt_get_datetype($fmt);
echo 'First Formatted output with datetype is ' . datefmt_format($fmt, 0);
$fmt = datefmt_create(
'en_US',
IntlDateFormatter::SHORT,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'Now datetype of the formatter is : ' . datefmt_get_datetype($fmt);
echo 'Second Formatted output with datetype is ' . datefmt_format($fmt, 0);
?>
Example #2 OO example
<?php
$fmt = new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'datetype of the formatter is : ' . $fmt->getDateType();
echo 'First Formatted output is ' . $fmt->format(0);
$fmt = new IntlDateFormatter(
'en_US',
IntlDateFormatter::SHORT,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'Now datetype of the formatter is : ' . $fmt->getDateType();
echo 'Second Formatted output is ' . $fmt->format(0);
?>
The above example will output:
datetype of the formatter is : 0 First Formatted output is Wednesday, December 31, 1969 4:00:00 PM PT Now datetype of the formatter is : 2 Second Formatted output is 12/31/69 4:00:00 PM PT
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
IntlDateFormatter::getErrorCode -- datefmt_get_error_code — Get the error code from last operation
Object oriented style
Procedural style
Get the error code from last operation. Returns error code from the last number formatting operation.
fmtThe formatter resource.
The error code, one of UErrorCode values. Initial value is U_ZERO_ERROR.
Example #1 datefmt_get_error_code() example
<?php
$fmt = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
$str = datefmt_format($fmt);
if (!$str) {
printf(
"ERROR: %s (%d)\n",
datefmt_get_error_message($fmt),
datefmt_get_error_code($fmt)
);
}
?>
Example #2 OO example
<?php
$fmt = new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
$str = $fmt->format();
if (!$str) {
printf(
"ERROR: %s (%d)\n",
$fmt->getErrorMessage(),
$fmt->getErrorCode()
);
}
?>
The above example will output:
ERROR: U_ZERO_ERROR (0)
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
IntlDateFormatter::getErrorMessage -- datefmt_get_error_message — Get the error text from the last operation
Object oriented style
Procedural style
Get the error text from the last operation.
fmtThe formatter resource.
Description of the last error.
Example #1 datefmt_get_error_message() example
<?php
$fmt = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
$str = datefmt_format($fmt);
if (!$str) {
printf(
"ERROR: %s (%d)\n",
datefmt_get_error_message($fmt),
datefmt_get_error_code($fmt)
);
}
?>
Example #2 OO example
<?php
$fmt = new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
$str = $fmt->format();
if(!$str) {
printf(
"ERROR: %s (%d)\n",
$fmt->getErrorMessage(),
$fmt->getErrorCode()
);
}
?>
The above example will output:
ERROR: U_ZERO_ERROR (0)
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
IntlDateFormatter::getLocale -- datefmt_get_locale — Get the locale used by formatter
Object oriented style
$which
] ) : stringProcedural style
Get locale used by the formatter.
fmtThe formatter resource
hich
You can choose between valid and actual locale (
Locale::VALID_LOCALE,
Locale::ACTUAL_LOCALE,
respectively). The default is the actual locale.
the locale of this formatter or 'false' if error
Example #1 datefmt_get_locale() example
<?php
$fmt = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'locale of the formatter is : " . datefmt_get_locale($fmt);
echo 'First Formatted output is " . datefmt_format($fmt, 0);
$fmt = datefmt_create(
'de-DE',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'locale of the formatter is : ' . datefmt_get_locale($fmt);
echo 'Second Formatted output is ' . datefmt_format($fmt, 0);
?>
Example #2 OO example
<?php
$fmt = new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'locale of the formatter is : ' . $fmt->getLocale();
echo 'First Formatted output is ' . $fmt->format(0);
$fmt = new IntlDateFormatter(
'de-DE',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'locale of the formatter is : ' . $fmt->getLocale();
echo 'Second Formatted output is ' . $fmt->format(0);
?>
The above example will output:
locale of the formatter is : en First Formatted output is Wednesday, December 31, 1969 4:00:00 PM PT locale of the formatter is : de Second Formatted output is Mittwoch, 31. Dezember 1969 16:00 Uhr GMT-08:00
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
IntlDateFormatter::getPattern -- datefmt_get_pattern — Get the pattern used for the IntlDateFormatter
Object oriented style
Procedural style
Get pattern used by the formatter.
fmtThe formatter resource.
The pattern string being used to format/parse.
Example #1 datefmt_get_pattern() example
<?php
$fmt = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN,
'MM/dd/yyyy'
);
echo 'pattern of the formatter is : ' . datefmt_get_pattern($fmt);
echo 'First Formatted output with pattern is ' . datefmt_format($fmt, 0);
datefmt_set_pattern($fmt,'yyyymmdd hh:mm:ss z');
echo 'Now pattern of the formatter is : ' . datefmt_get_pattern($fmt);
echo 'Second Formatted output with pattern is ' . datefmt_format($fmt, 0);
?>
Example #2 OO example
<?php
$fmt = new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN,
'MM/dd/yyyy'
);
echo 'pattern of the formatter is : ' . $fmt->getPattern();
echo 'First Formatted output is ' . $fmt->format(0);
$fmt->setPattern('yyyymmdd hh:mm:ss z');
echo 'Now pattern of the formatter is : ' . $fmt->getPattern();
echo 'Second Formatted output is ' . $fmt->format(0);
?>
The above example will output:
pattern of the formatter is : MM/dd/yyyy First Formatted output is 12/31/1969 Now pattern of the formatter is : yyyymmdd hh:mm:ss z Second Formatted output is 19690031 04:00:00 PST
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
IntlDateFormatter::getTimeType -- datefmt_get_timetype — Get the timetype used for the IntlDateFormatter
Object oriented style
Procedural style
Return time type used by the formatter.
fmtThe formatter resource.
The current date type value of the formatter.
Example #1 datefmt_get_timetype() example
<?php
$fmt = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'timetype of the formatter is : ' . datefmt_get_timetype($fmt);
echo 'First Formatted output with timetype is ' . datefmt_format($fmt, 0);
$fmt = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::SHORT,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'Now timetype of the formatter is : ' . datefmt_get_timetype($fmt);
echo 'Second Formatted output with timetype is ' . datefmt_format($fmt, 0);
?>
Example #2 OO example
<?php
$fmt = new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'timetype of the formatter is : ' . $fmt->getTimeType();
echo 'First Formatted output is ' . $fmt->format(0);
$fmt = new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::SHORT,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'Now timetype of the formatter is : ' . $fmt->getTimeType();
echo 'Second Formatted output is ' . $fmt->format(0);
?>
The above example will output:
timetype of the formatter is : 0 First Formatted output is Wednesday, December 31, 1969 4:00:00 PM PT Now timetype of the formatter is : 3 Second Formatted output is Wednesday, December 31, 1969 4:00 PM
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
IntlDateFormatter::getTimeZoneId -- datefmt_get_timezone_id — Get the timezone-id used for the IntlDateFormatter
Object oriented style
Procedural style
Get the timezone-id used for the IntlDateFormatter.
fmtThe formatter resource.
ID string for the time zone used by this formatter.
Example #1 datefmt_get_timezone_id() example
<?php
$fmt = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'timezone_id of the formatter is : ' . datefmt_get_timezone_id($fmt);
datefmt_set_timezone_id($fmt, 'CN');
echo 'Now timezone_id of the formatter is : ' . datefmt_get_timezone_id($fmt);
?>
Example #2 OO example
<?php
$fmt = new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'timezone_id of the formatter is : ' . $fmt->getTimezoneId();
$fmt->setTimezoneId('CN');
echo 'Now timezone_id of the formatter is : ' . $fmt->getTimezoneId();
?>
The above example will output:
timezone_id of the formatter is : America/Los_Angeles Now timezone_id of the formatter is : CN
(PHP 5 >= 5.5.0, PHP 7, PECL intl >= 3.0.0)
IntlDateFormatter::getCalendarObject -- datefmt_get_calendar_object — Get copy of formatterʼs calendar object
Object oriented style
Procedural style
Obtain a copy of the calendar object used internally by this formatter. This calendar will have a type (as in gregorian, japanese, buddhist, roc, persian, islamic, etc.) and a timezone that match the type and timezone used by the formatter. The date/time of the object is unspecified.
This function has no parameters.
A copy of the internal calendar object used by this formatter.
Example #1 IntlDateFormatter::getCalendarObject() example
<?php
$formatter = IntlDateFormatter::create(
"fr_FR@calendar=islamic",
NULL,
NULL,
"GMT-01:00",
IntlDateFormatter::TRADITIONAL
);
$cal = $formatter->getCalendarObject();
var_dump(
$cal->getType(),
$cal->getTimeZone(),
$cal->getLocale(Locale::VALID_LOCALE)
);
The above example will output:
string(7) "islamic"
object(IntlTimeZone)#3 (4) {
["valid"]=>
bool(true)
["id"]=>
string(9) "GMT-01:00"
["rawOffset"]=>
int(-3600000)
["currentOffset"]=>
int(-3600000)
}
string(5) "fr_FR"
(PHP 5 >= 5.5.0, PHP 7, PECL intl >= 3.0.0)
IntlDateFormatter::getTimeZone -- datefmt_get_timezone — Get formatterʼs timezone
Object oriented style
Procedural style
Returns an IntlTimeZone object representing the timezone that will be used by this object to format dates and times. When formatting IntlCalendar and DateTime objects with this IntlDateFormatter, the timezone used will be the one returned by this method, not the one associated with the objects being formatted.
This function has no parameters.
The associated IntlTimeZone
object or FALSE on failure.
Example #1 IntlDateFormatter::getTimeZone() examples
<?php
$madrid = IntlDateFormatter::create(NULL, NULL, NULL, 'Europe/Madrid');
$lisbon = IntlDateFormatter::create(NULL, NULL, NULL, 'Europe/Lisbon');
var_dump($madrid->getTimezone());
echo $madrid->getTimezone()->getDisplayName(
false, IntlTimeZone::DISPLAY_GENERIC_LOCATION, "en_US"), "\n";
echo $lisbon->getTimeZone()->getId(), "\n";
//The id can also be retrieved with ->getTimezoneId()
echo $lisbon->getTimeZoneId(), "\n";
The above example will output:
object(IntlTimeZone)#4 (4) {
["valid"]=>
bool(true)
["id"]=>
string(13) "Europe/Madrid"
["rawOffset"]=>
int(3600000)
["currentOffset"]=>
int(7200000)
}
Spain Time
Europe/Lisbon
Europe/Lisbon
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
IntlDateFormatter::isLenient -- datefmt_is_lenient — Get the lenient used for the IntlDateFormatter
Object oriented style
Procedural style
Check if the parser is strict or lenient in interpreting inputs that do not match the pattern exactly.
fmtThe formatter resource.
TRUE if parser is lenient, FALSE if parser is strict. By default the parser is lenient.
Example #1 datefmt_is_lenient() example
<?php
$fmt = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN,
'dd/mm/yyyy'
);
echo 'lenient of the formatter is : ';
if ($fmt->isLenient()) {
echo 'TRUE';
} else {
echo 'FALSE';
}
datefmt_parse($fmt, '35/13/1971');
echo "\n Trying to do parse('35/13/1971').\nResult is : " . datefmt_parse($fmt, '35/13/1971');
if (intl_get_error_code() != 0) {
echo "\nError_msg is : " . intl_get_error_message();
echo "\nError_code is : " . intl_get_error_code();
}
datefmt_set_lenient($fmt,false);
echo 'Now lenient of the formatter is : ';
if ($fmt->isLenient()) {
echo 'TRUE';
} else {
echo 'FALSE';
}
datefmt_parse($fmt, '35/13/1971');
echo "\n Trying to do parse('35/13/1971').Result is : " . datefmt_parse($fmt, '35/13/1971');
if (intl_get_error_code() != 0) {
echo "\nError_msg is : " . intl_get_error_message();
echo "\nError_code is : " . intl_get_error_code();
}
?>
Example #2 OO example
<?php
$fmt = new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN,
"dd/mm/yyyy"
);
echo "lenient of the formatter is : ";
if ($fmt->isLenient()) {
echo 'TRUE';
} else {
echo 'FALSE';
}
$fmt->parse('35/13/1971');
echo "\n Trying to do parse('35/13/1971').\nResult is : " . $fmt->parse('35/13/1971');
if (intl_get_error_code() != 0){
echo "\nError_msg is : " . intl_get_error_message();
echo "\nError_code is : " . intl_get_error_code();
}
$fmt->setLenient(FALSE);
echo 'Now lenient of the formatter is : ';
if ($fmt->isLenient()) {
echo 'TRUE';
} else {
echo 'FALSE';
}
$fmt->parse('35/13/1971');
echo "\n Trying to do parse('35/13/1971').\nResult is : " . $fmt->parse('35/13/1971');
if (intl_get_error_code() != 0) {
echo "\nError_msg is : " . intl_get_error_message();
echo "\nError_code is : " . intl_get_error_code();
}
?>
The above example will output:
lenient of the formatter is : TRUE
Trying to do parse('35/13/1971').
Result is : -2147483
Now lenient of the formatter is : FALSE
Trying to do parse('35/13/1971').
Result is :
Error_msg is : Date parsing failed: U_PARSE_ERROR
Error_code is : 9
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
IntlDateFormatter::localtime -- datefmt_localtime — Parse string to a field-based time value
Object oriented style
$value
[, int &$position
] ) : arrayProcedural style
Converts string $value to a field-based time value ( an array of various fields), starting at $parse_pos and consuming as much of the input value as possible.
fmtThe formatter resource
valuestring to convert to a time
positionPosition at which to start the parsing in $value (zero-based). If no error occurs before $value is consumed, $parse_pos will contain -1 otherwise it will contain the position at which parsing ended . If $parse_pos > strlen($value), the parse fails immediately.
Localtime compatible array of integers : contains 24 hour clock value in tm_hour field
Example #1 datefmt_localtime() example
<?php
$fmt = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
$arr = datefmt_localtime($fmt, 'Wednesday, December 31, 1969 4:00:00 PM PT', 0);
echo 'First parsed output is ';
if ($arr) {
foreach ($arr as $key => $value) {
echo "$key : $value , ";
}
}
?>
Example #2 OO example
<?php
$fmt = new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
$arr = $fmt->localtime('Wednesday, December 31, 1969 4:00:00 PM PT', 0);
echo 'First parsed output is ';
if ($arr) {
foreach ($arr as $key => $value) {
echo "$key : $value , ";
}
}
?>
The above example will output:
First parsed output is tm_sec : 0 , tm_min : 0 , tm_hour : 16 , tm_year : 1969 , tm_mday : 31 , tm_wday : 4 , tm_yday : 365 , tm_mon : 11 , tm_isdst : 0 ,
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
IntlDateFormatter::parse -- datefmt_parse — Parse string to a timestamp value
Object oriented style
$value
[, int &$position
] ) : intProcedural style
Converts string $value to an incremental time value, starting at $parse_pos and consuming as much of the input value as possible.
fmtThe formatter resource
valuestring to convert to a time
positionPosition at which to start the parsing in $value (zero-based). If no error occurs before $value is consumed, $parse_pos will contain -1 otherwise it will contain the position at which parsing ended (and the error occurred). This variable will contain the end position if the parse fails. If $parse_pos > strlen($value), the parse fails immediately.
timestamp parsed value, or FALSE if value can't be parsed.
Example #1 OO example
<?php
$fmt = new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'First parsed output is ' . $fmt->parse('Wednesday, December 20, 1989 4:00:00 PM PT');
$fmt = new IntlDateFormatter(
'de-DE',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
?>
Example #2 datefmt_parse() example
<?php
$fmt = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'First parsed output is ' . datefmt_parse($fmt, 'Wednesday, December 20, 1989 4:00:00 PM PT');
$fmt = datefmt_create(
'de-DE',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'Second parsed output is ' . datefmt_parse($fmt, 'Mittwoch, 20. Dezember 1989 16:00 Uhr GMT-08:00');
?
The above example will output:
First parsed output is 630201600 Second parsed output is 630201600
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
IntlDateFormatter::setCalendar -- datefmt_set_calendar — Sets the calendar type used by the formatter
Object oriented style
Procedural style
Sets the calendar or calendar type used by the formatter.
fmtThe formatter resource.
which
This can either be: the calendar
type to use (default is
IntlDateFormatter::GREGORIAN, which is also used if
NULL is specified) or an
IntlCalendar object.
Any IntlCalendar object passed in will be cloned; no modifications will be made to the argument object.
The timezone of the formatter will only be kept if an IntlCalendar object is not passed, otherwise the new timezone will be that of the passed object.
Returns TRUE on success or FALSE on failure.
Example #1 datefmt_set_calendar() example
<?php
$fmt = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'calendar of the formatter is : ' . datefmt_get_calendar($fmt);
datefmt_set_calendar($fmt, IntlDateFormatter::TRADITIONAL);
echo 'Now calendar of the formatter is : ' . datefmt_get_calendar($fmt);
?>
Example #2 OO example
<?php
$fmt = new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'calendar of the formatter is : ' . $fmt->getCalendar();
$fmt->setCalendar(IntlDateFormatter::TRADITIONAL);
echo 'Now calendar of the formatter is : ' . $fmt->getCalendar();
?>
The above example will output:
calendar of the formatter is : 1 Now calendar of the formatter is : 0
Example #3 Example with IntlCalendar argument
<?php
$time = strtotime("2013-03-03 00:00:00 UTC");
$formatter = IntlDateFormatter::create("en_US", NULL, NULL, "Europe/Amsterdam");
echo "before: ", $formatter->format($time), "\n";
/* note that the calendar's locale is not used! */
$formatter->setCalendar(IntlCalendar::createInstance(
"America/New_York", "pt_PT@calendar=islamic"));
echo "after: ", $formatter->format($time), "\n";
The above example will output:
before: Sunday, March 3, 2013 at 1:00:00 AM Central European Standard Time after: Saturday, Rabiʻ II 20, 1434 at 7:00:00 PM Eastern Standard Time
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
IntlDateFormatter::setLenient -- datefmt_set_lenient — Set the leniency of the parser
Object oriented style
$lenient
) : boolProcedural style
Define if the parser is strict or lenient in interpreting inputs that do not match the pattern exactly. Enabling lenient parsing allows the parser to accept otherwise flawed date or time patterns, parsing as much as possible to obtain a value. Extra space, unrecognized tokens, or invalid values ("February 30th") are not accepted.
fmtThe formatter resource
lenient
Sets whether the parser is lenient or not, default is TRUE (lenient).
Returns TRUE on success or FALSE on failure.
Example #1 datefmt_set_lenient() example
<?php
$fmt = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN,
'dd/MM/yyyy'
);
echo 'lenient of the formatter is : ';
if ($fmt->isLenient()) {
echo 'TRUE';
} else {
echo 'FALSE';
}
datefmt_parse($fmt, '35/13/1971');
echo "\n Trying to do parse('35/13/1971').\nResult is : " . datefmt_parse($fmt, '35/13/1971');
if (intl_get_error_code() != 0) {
echo "\nError_msg is : " . intl_get_error_message();
echo "\nError_code is : " . intl_get_error_code();
}
datefmt_set_lenient($fmt, false);
echo "\nNow lenient of the formatter is : ";
if ($fmt->isLenient()) {
echo 'TRUE';
} else {
echo 'FALSE';
}
datefmt_parse($fmt, '35/13/1971');
echo "\nTrying to do parse('35/13/1971').\nResult is : " . datefmt_parse($fmt, '35/13/1971');
if (intl_get_error_code() != 0) {
echo "\nError_msg is : ".intl_get_error_message();
echo "\nError_code is : ".intl_get_error_code();
}
?>
Example #2 OO example
<?php
$fmt = new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN,
'dd/MM/yyyy'
);
echo 'lenient of the formatter is : ';
if ($fmt->isLenient()) {
echo 'TRUE';
} else {
echo 'FALSE';
}
$fmt->parse('35/13/1971');
echo "\n Trying to do parse('35/13/1971').\nResult is : " . $fmt->parse('35/13/1971');
if (intl_get_error_code() != 0) {
echo "\nError_msg is : " . intl_get_error_message();
echo "\nError_code is : " . intl_get_error_code();
}
$fmt->setLenient(FALSE);
echo "\nNow lenient of the formatter is : ";
if ($fmt->isLenient()) {
echo 'TRUE';
} else {
echo 'FALSE';
}
$fmt->parse('35/13/1971');
echo "\n Trying to do parse('35/13/1971').\nResult is : " . $fmt->parse('35/13/1971');
if (intl_get_error_code() != 0) {
echo "\nError_msg is : " . intl_get_error_message();
echo "\nError_code is : " . intl_get_error_code();
}
?>
The above example will output:
lenient of the formatter is : TRUE
Trying to do parse('35/13/1971').
Result is : 66038400
Now lenient of the formatter is : FALSE
Trying to do parse('35/13/1971').
Result is :
Error_msg is : Date parsing failed: U_PARSE_ERROR
Error_code is : 9
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
IntlDateFormatter::setPattern -- datefmt_set_pattern — Set the pattern used for the IntlDateFormatter
Object oriented style
$pattern
) : boolProcedural style
Set the pattern used for the IntlDateFormatter.
fmtThe formatter resource.
patternNew pattern string to use. Possible patterns are documented at » http://userguide.icu-project.org/formatparse/datetime.
Returns TRUE on success or FALSE on failure.
Bad formatstrings are usually the cause of the failure.
Example #1 datefmt_set_pattern() example
<?php
$fmt = datefmt_create(
'en_US',
IntlDateFormatter::FULL,IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN,
'MM/dd/yyyy'
);
echo 'pattern of the formatter is : ' . datefmt_get_pattern($fmt);
echo 'First Formatted output with pattern is ' . datefmt_format($fmt, 0);
datefmt_set_pattern($fmt, 'yyyymmdd hh:mm:ss z');
echo 'Now pattern of the formatter is : ' . datefmt_get_pattern($fmt);
echo 'Second Formatted output with pattern is ' . datefmt_format($fmt, 0);
?>
Example #2 OO example
<?php
$fmt = new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN,
'MM/dd/yyyy'
);
echo 'pattern of the formatter is : ' . $fmt->getPattern();
echo 'First Formatted output is ' . $fmt->format(0);
$fmt->setPattern('yyyymmdd hh:mm:ss z');
echo 'Now pattern of the formatter is : ' . $fmt->getPattern();
echo 'Second Formatted output is ' . $fmt->format(0);
?>
The above example will output:
pattern of the formatter is : MM/dd/yyyy First Formatted output with pattern is 12/31/1969 Now pattern of the formatter is : yyyymmdd hh:mm:ss z Second Formatted output with pattern is 19690031 04:00:00 PST
(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
IntlDateFormatter::setTimeZoneId -- datefmt_set_timezone_id — Sets the time zone to use
This function was DEPRECATED in PHP 5.5.0, and REMOVED in PHP 7.0.0.
Alternatives to this function include:
Object oriented style
$zone
) : boolProcedural style
Sets the time zone to use.
fmtThe formatter resource.
zone
The time zone ID string of the time zone to use.
If NULL or the empty string, the default time zone for the runtime is used.
Returns TRUE on success or FALSE on failure.
| Version | Description |
|---|---|
| 7.0.0 | This function has been removed. |
| 5.5.0 | This function has been deprecated. |
Example #1 datefmt_set_timezone_id() example
<?php
$fmt = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'timezone_id of the formatter is : ' . datefmt_get_timezone_id($fmt);
datefmt_set_timezone_id($fmt, 'CN');
echo 'Now timezone_id of the formatter is : ' . datefmt_get_timezone_id($fmt);
?>
Example #2 OO example
<?php
$fmt = new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo 'timezone_id of the formatter is : ' . $fmt->getTimezoneId();
$fmt->setTimezoneId('CN');
echo 'Now timezone_id of the formatter is : ' . $fmt->getTimezoneId();
?>
The above example will output:
timezone_id of the formatter is : America/Los_Angeles Now timezone_id of the formatter is : CN
(PHP 5 >= 5.5.0, PHP 7, PECL intl >= 3.0.0)
IntlDateFormatter::setTimeZone -- datefmt_set_timezone — Sets formatterʼs timezone
Object oriented style
Procedural style
Sets the timezone used for the IntlDateFormatter. object.
fmtThe formatter resource.
zoneThe timezone to use for this formatter. This can be specified in the following forms:
NULL, in which case the default timezone will be used, as specified in
the ini setting date.timezone or
through the function date_default_timezone_set() and as
returned by date_default_timezone_get().
An IntlTimeZone, which will be used directly.
A DateTimeZone. Its identifier will be extracted and an ICU timezone object will be created; the timezone will be backed by ICUʼs database, not PHPʼs.
A string, which should be a valid ICU timezone identifier.
See IntlTimeZone::createTimeZoneIDEnumeration(). Raw
offsets such as "GMT+08:30" are also accepted.
Returns TRUE on success and FALSE on failure.
Example #1 IntlDateFormatter::setTimeZone() examples
<?php
ini_set('date.timezone', 'Europe/Amsterdam');
$formatter = IntlDateFormatter::create(NULL, NULL, NULL, "UTC");
$formatter->setTimeZone(NULL);
echo "NULL\n ", $formatter->getTimeZone()->getId(), "\n";
$formatter->setTimeZone(IntlTimeZone::createTimeZone('Europe/Lisbon'));
echo "IntlTimeZone\n ", $formatter->getTimeZone()->getId(), "\n";
$formatter->setTimeZone(new DateTimeZone('Europe/Paris'));
echo "DateTimeZone\n ", $formatter->getTimeZone()->getId(), "\n";
$formatter->setTimeZone('Europe/Rome');
echo "String\n ", $formatter->getTimeZone()->getId(), "\n";
$formatter->setTimeZone('GMT+00:30');
print_r($formatter->getTimeZone());
The above example will output:
NULL
Europe/Amsterdam
IntlTimeZone
Europe/Lisbon
DateTimeZone
Europe/Paris
String
Europe/Rome
IntlTimeZone Object
(
[valid] => 1
[id] => GMT+00:30
[rawOffset] => 1800000
[currentOffset] => 1800000
)
(PHP 5 >= 5.3.2, PHP 7, PECL intl >= 2.0.0)
Localized software products often require sets of data that are to be customized depending on current locale, e.g.: messages, labels, formatting patterns. ICU resource mechanism allows to define sets of resources that the application can load on locale basis, while accessing them in unified locale-independent fashion.
This class implements access to ICU resource data files. These files are binary data arrays which ICU uses to store the localized data.
ICU resource bundle can hold simple resources and complex resources. Complex resources are containers which can be either integer-indexed or string-indexed (just like PHP arrays). Simple resources can be of the following types: string, integer, binary data field or integer array.
ResourceBundle supports direct access to the data through array access pattern and iteration via foreach, as well as access via class methods. The result will be PHP value for simple resources and ResourceBundle object for complex ones. All resources are read-only.
(PHP 5 >= 5.3.2, PHP 7, PECL intl >= 2.0.0)
ResourceBundle::count -- resourcebundle_count — Get number of elements in the bundle
Object oriented style
Procedural style
Get the number of elements in the bundle.
Returns number of elements in the bundle.
Example #1 resourcebundle_count() example
<?php
$r = resourcebundle_create( 'es', "/usr/share/data/myapp");
echo resourcebundle_count($r);
?>
Example #2 OO example
<?php
$r = new ResourceBundle( 'es', "/usr/share/data/myapp");
echo $r->count();
?>
The above example will output:
42
(PHP 5 >= 5.3.2, PHP 7, PECL intl >= 2.0.0)
ResourceBundle::create -- resourcebundle_create -- ResourceBundle::__construct — Create a resource bundle
Object oriented style (method)
$locale
, string $bundlename
[, bool $fallback
] ) : ResourceBundleProcedural style
Object oriented style (constructor):
$locale
, string $bundlename
[, bool $fallback
] )Creates a resource bundle.
localeLocale for which the resources should be loaded (locale name, e.g. en_CA).
bundlenameThe directory where the data is stored or the name of the .dat file.
fallbackWhether locale should match exactly or fallback to parent locale is allowed.
Returns ResourceBundle object or NULL on error.
Example #1 resourcebundle_create() example
<?php
$r = resourcebundle_create( 'es', "/usr/share/data/myapp");
echo $r['teststring'];
?>
Example #2 ResourceBundle::create() example
<?php
$r = ResourceBundle::create( 'es', "/usr/share/data/myapp");
echo $r['teststring'];
?>
The above example will output:
¡Hola, mundo!
(PHP 5 >= 5.3.2, PHP 7, PECL intl >= 2.0.0)
ResourceBundle::getErrorCode -- resourcebundle_get_error_code — Get bundle's last error code
Object oriented style
Procedural style
Get error code from the last function performed by the bundle object.
Returns error code from last bundle object call.
Example #1 resourcebundle_get_error_code() example
<?php
$r = resourcebundle_create( 'es', "/usr/share/data/myapp");
echo $r['somestring'];
if(intl_is_failure(resourcebundle_get_error_code($r))) {
report_error("Bundle error");
}
?>
Example #2 OO example
<?php
$r = new ResourceBundle( 'es', "/usr/share/data/myapp");
echo $r['somestring'];
if(intl_is_failure(ResourceBundle::getErrorCode($r))) {
report_error("Bundle error");
}
?>
(PHP 5 >= 5.3.2, PHP 7, PECL intl >= 2.0.0)
ResourceBundle::getErrorMessage -- resourcebundle_get_error_message — Get bundle's last error message
Object oriented style
Procedural style
Get error message from the last function performed by the bundle object.
Returns error message from last bundle object's call.
Example #1 resourcebundle_get_error_message() example
<?php
$r = resourcebundle_create( 'es', "/usr/share/data/myapp");
echo $r['somestring'];
if(intl_is_failure(resourcebundle_get_error_code($r))) {
report_error("Bundle error: ".resourcebundle_get_error_message($r));
}
?>
Example #2 OO example
<?php
$r = new ResourceBundle( 'es', "/usr/share/data/myapp");
echo $r['somestring'];
if(intl_is_failure(ResourceBundle::getErrorCode($r))) {
report_error("Bundle error: ".ResourceBundle::getErrorMessage($r));
}
?>
(PHP 5 >= 5.3.2, PHP 7, PECL intl >= 2.0.0)
ResourceBundle::get -- resourcebundle_get — Get data from the bundle
Object oriented style
Procedural style
Get the data from the bundle by index or string key.
rResourceBundle object.
indexData index, must be string or integer.
fallbackWhether locale should match exactly or fallback to parent locale is allowed.
Returns the data located at the index or NULL on error. Strings, integers and binary data strings
are returned as corresponding PHP types, integer array is returned as PHP array. Complex types are
returned as ResourceBundle object.
Example #1 resourcebundle_get() example
<?php
$r = resourcebundle_create( 'es', "/usr/share/data/myapp");
echo resourcebundle_get($r, 'somestring');
?>
Example #2 OO example
<?php
$r = new ResourceBundle( 'es', "/usr/share/data/myapp");
echo $r->get('somestring');
?>
The above example will output:
?Hola, mundo!
(PHP 5 >= 5.3.2, PHP 7, PECL intl >= 2.0.0)
ResourceBundle::getLocales -- resourcebundle_locales — Get supported locales
Object oriented style
$bundlename
) : arrayProcedural style
$bundlename
) : arrayGet available locales from ResourceBundle name.
bundlenamePath of ResourceBundle for which to get available locales, or empty string for default locales list.
Returns the list of locales supported by the bundle.
Example #1 resourcebundle_locales() example
<?php
$bundle = "/user/share/data/myapp";
echo join(PHP_EOL, resourcebundle_locales($bundle));
?>
The above example will output something similar to:
es root
Example #2 OO example
<?php
$bundle = "/usr/share/data/myapp";
$r = new ResourceBundle( 'es', $bundle);
echo join("\n", $r->getLocales($bundle));
?>
The above example will output something similar to:
es root
(PHP 5 >= 5.4.0, PHP 7, PECL intl >= 2.0.0)
This class is provided because Unicode contains large number of characters and incorporates the varied writing systems of the world and their incorrect usage can expose programs or systems to possible security attacks using characters similarity.
Provided methods allow to check whether an individual string is likely an attempt
at confusing the reader (spoof detection), such as "pаypаl"
spelled with Cyrillic 'а' characters.
Spoofchecker::ASCIISpoofchecker::HIGHLY_RESTRICTIVESpoofchecker::MODERATELY_RESTRICTIVESpoofchecker::MINIMALLY_RESTRICTIVESpoofchecker::UNRESTRICTIVESpoofchecker::SINGLE_SCRIPT_RESTRICTIVESpoofchecker::SINGLE_SCRIPT_CONFUSABLESpoofchecker::MIXED_SCRIPT_CONFUSABLESpoofchecker::WHOLE_SCRIPT_CONFUSABLESpoofchecker::ANY_CASESpoofchecker::SINGLE_SCRIPTSpoofchecker::INVISIBLESpoofchecker::CHAR_LIMIT| Version | Description |
|---|---|
| 7.3.0 |
Class constants used by Spoofchecker::setRestrictionLevel() such as Spoofchecker::ASCII, Spoofchecker::HIGHLY_RESTRICTIVE, Spoofchecker::MODERATELY_RESTRICTIVE, Spoofchecker::MINIMALLY_RESTRICTIVE, Spoofchecker::UNRESTRICTIVE, Spoofchecker::SINGLE_SCRIPT_RESTRICTIVE has been added.
|
(PHP 5 >= 5.4.0, PHP 7, PECL intl >= 2.0.0)
Spoofchecker::areConfusable — Checks if given strings can be confused
$str1
, string $str2
[, string &$error
] ) : boolChecks whether two given strings can easily be mistaken.
str1First string to check.
str2Second string to check.
errorThis variable is set by-reference to string containing an error, if there were any.
Returns TRUE if two given strings can be confused, FALSE otherwise.
Example #1 Spoofchecker::areConfusable() example
<?php
$checker = new Spoofchecker();
$checker->areConfusable('google.com', 'goog1e.com'); // true
// Lower l can be confused with digit one
$checker->areConfusable('google.com', 'g00g1e.com'); // false
// Zero (0) cannot be easily confused with "o" letter
(PHP 5 >= 5.4.0, PHP 7, PECL intl >= 2.0.0)
Spoofchecker::__construct — Constructor
Creates new instance of Spoofchecker.
This function has no parameters.
Returns Spoofchecker instance.
(PHP 5 >= 5.4.0, PHP 7, PECL intl >= 2.0.0)
Spoofchecker::isSuspicious — Checks if a given text contains any suspicious characters
$text
[, string &$error
] ) : boolChecks if given string contains any suspicious characters like letters which are almost identical visually, but are Unicode characters from different sets.
textString to test.
errorThis variable is set by-reference to string containing an error, if there were any.
Returns TRUE if there are suspicious characters, FALSE otherwise.
Example #1 Spoofchecker::isSuspicious() example
<?php
$checker = new Spoofchecker();
$checker->isSuspicious('google.com'); // FALSE: only ASCII characters
$checker->isSuspicious('Рaypal.com'); // TRUE
// The first letter is from Cyrylic, not a regular latin "P"
(PHP 5 >= 5.4.0, PHP 7, PECL intl >= 2.0.0)
Spoofchecker::setAllowedLocales — Locales to use when running checks
$locale_list
) : void
This function is currently not documented; only its argument list is available.
locale_list
(PHP 5 >= 5.4.0, PHP 7, PECL intl >= 2.0.0)
Spoofchecker::setChecks — Set the checks to run
$checks
) : void
This function is currently not documented; only its argument list is available.
checks
(PHP 5 >= 5.4.0, PHP 7, PECL intl >= 2.0.0)
Transliterator provides transliteration of strings.
Transliterator::FORWARDTransliterator::REVERSE(PHP 5 >= 5.4.0, PHP 7, PECL intl >= 2.0.0)
Transliterator::__construct — Private constructor to deny instantiation
This method should not be called. Its only purpose is to deny instantiation with the new operator.
Use the factory methods Transliterator::create() or Transliterator::createFromRules() instead.
This function has no parameters.
This method should not be executed. If it is (e.g. through reflection), then its return value is unspecified.
(PHP 5 >= 5.4.0, PHP 7, PECL intl >= 2.0.0)
Transliterator::create -- transliterator_create — Create a transliterator
Object oriented style
Procedural style
Opens a Transliterator by ID.
This function is currently not documented; only its argument list is available.
idThe ID. A list of all registered transliterator IDs can be retrieved by using Transliterator::listIDs().
directionThe direction, defaults to Transliterator::FORWARD. May also be set to Transliterator::REVERSE.
Returns a Transliterator object on success,
or NULL on failure.
(PHP 5 >= 5.4.0, PHP 7, PECL intl >= 2.0.0)
Transliterator::createFromRules -- transliterator_create_from_rules — Create transliterator from rules
Object oriented style
$rules
[, string $direction
] ) : TransliteratorProcedural style
Creates a Transliterator from rules.
This function is currently not documented; only its argument list is available.
rulesThe rules as defined in Transform Rules Syntax of UTS #35: Unicode LDML.
directionThe direction, defaults to >Transliterator::FORWARD. May also be set to Transliterator::REVERSE.
Returns a Transliterator object on success,
or NULL on failure.
(PHP 5 >= 5.4.0, PHP 7, PECL intl >= 2.0.0)
Transliterator::createInverse -- transliterator_create_inverse — Create an inverse transliterator
Object oriented style
Procedural style
Opens the inverse transliterator.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Returns a Transliterator object on success,
or NULL on failure
(PHP 5 >= 5.4.0, PHP 7, PECL intl >= 2.0.0)
Transliterator::getErrorCode -- transliterator_get_error_code — Get last error code
Object oriented style
Procedural style
Gets the last error code for this transliterator.
This function is currently not documented; only its argument list is available.
trans
The error code on success,
or FALSE if none exists, or on failure.
(PHP 5 >= 5.4.0, PHP 7, PECL intl >= 2.0.0)
Transliterator::getErrorMessage -- transliterator_get_error_message — Get last error message
Object oriented style
Procedural style
Gets the last error message for this transliterator.
This function is currently not documented; only its argument list is available.
trans
The error message on success,
or FALSE if none exists, or on failure.
(PHP 5 >= 5.4.0, PHP 7, PECL intl >= 2.0.0)
Transliterator::listIDs -- transliterator_list_ids — Get transliterator IDs
Object oriented style
Procedural style
Returns an array with the registered transliterator IDs.
This function has no parameters.
An array of registered transliterator IDs on success,
or FALSE on failure.
Example #1 Retrieving the registered transliterator IDs
<?php
print_r(Transliterator::listIDs());
?>
The above example will output something similar to:
Array
(
[0] => ASCII-Latin
[1] => Accents-Any
[2] => Amharic-Latin/BGN
[3] => Any-Accents
[4] => Any-Publishing
...
[650] => Any-ps_Latn/BGN
[651] => Any-tk/BGN
[652] => Any-ch_FONIPA
[653] => Any-cs_FONIPA
[654] => Any-cy_FONIPA
)
(PHP 5 >= 5.4.0, PHP 7, PECL intl >= 2.0.0)
Transliterator::transliterate -- transliterator_transliterate — Transliterate a string
Object oriented style
$subject
[, int $start
[, int $end
]] ) : stringProcedural style
$transliterator
, string $subject
[, int $start
[, int $end
]] )Transforms a string or part thereof using an ICU transliterator.
transliteratorIn the procedural version, either a Transliterator or a string from which a Transliterator can be built.
subjectThe string to be transformed.
startThe start index (in UTF-16 code units) from which the string will start to be transformed, inclusive. Indexing starts at 0. The text before will be left as is.
endThe end index (in UTF-16 code units) until which the string will be transformed, exclusive. Indexing starts at 0. The text after will be left as is.
The transformed string on success, or FALSE on failure.
Example #1 Converting escaped UTF-16 code units
<?php
$s = "\u304A\u65E9\u3046\u3054\u3056\u3044\u307E\u3059";
echo transliterator_transliterate("Hex-Any/Java", $s), "\n";
//now the reverse operation with a supplementary character
$supplChar = html_entity_decode('𝄞');
echo mb_strlen($supplChar, "UTF-8"), "\n";
$encSupplChar = transliterator_transliterate("Any-Hex/Java", $supplChar);
//echoes two encoded UTF-16 code units
echo $encSupplChar, "\n";
//and back
echo transliterator_transliterate("Hex-Any/Java", $encSupplChar), "\n";
?>
The above example will output something similar to:
お早うございます 1 \uD834\uDD1E 𝄞
(PHP 5 >= 5.5.0, PHP 7)
A “break iterator” is an ICU object that exposes methods for locating boundaries in text (e.g. word or sentence boundaries). The PHP IntlBreakIterator serves as the base class for all types of ICU break iterators. Where extra functionality is available, the intl extension may expose the ICU break iterator with suitable subclasses, such as IntlRuleBasedBreakIterator or IntlCodePointBreakIterator.
This class implements Traversable. Traversing an
IntlBreakIterator yields non-negative integer
values representing the successive locations of the text boundaries,
expressed as UTF-8 code units (byte) counts, taken from the beginning of
the text (which has the location 0). The keys yielded
by the iterator simply form the sequence of natural numbers
{0, 1, 2, …}.
$key_type = IntlPartsIterator::KEY_SEQUENTIAL
] ) : IntlPartsIteratorIntlBreakIterator::DONEIntlBreakIterator::WORD_NONEIntlBreakIterator::WORD_NONE_LIMITIntlBreakIterator::WORD_NUMBERIntlBreakIterator::WORD_NUMBER_LIMITIntlBreakIterator::WORD_LETTERIntlBreakIterator::WORD_LETTER_LIMITIntlBreakIterator::WORD_KANAIntlBreakIterator::WORD_KANA_LIMITIntlBreakIterator::WORD_IDEOIntlBreakIterator::WORD_IDEO_LIMITIntlBreakIterator::LINE_SOFTIntlBreakIterator::LINE_SOFT_LIMITIntlBreakIterator::LINE_HARDIntlBreakIterator::LINE_HARD_LIMITIntlBreakIterator::SENTENCE_TERMIntlBreakIterator::SENTENCE_TERM_LIMITIntlBreakIterator::SENTENCE_SEPIntlBreakIterator::SENTENCE_SEP_LIMIT(PHP 5 >= 5.5.0, PHP 7)
IntlBreakIterator::__construct — Private constructor for disallowing instantiation
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7)
IntlBreakIterator::createCharacterInstance — Create break iterator for boundaries of combining character sequences
This function is currently not documented; only its argument list is available.
locale
(PHP 5 >= 5.5.0, PHP 7)
IntlBreakIterator::createCodePointInstance — Create break iterator for boundaries of code points
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7)
IntlBreakIterator::createLineInstance — Create break iterator for logically possible line breaks
This function is currently not documented; only its argument list is available.
locale
(PHP 5 >= 5.5.0, PHP 7)
IntlBreakIterator::createSentenceInstance — Create break iterator for sentence breaks
This function is currently not documented; only its argument list is available.
locale
(PHP 5 >= 5.5.0, PHP 7)
IntlBreakIterator::createTitleInstance — Create break iterator for title-casing breaks
This function is currently not documented; only its argument list is available.
locale
(PHP 5 >= 5.5.0, PHP 7)
IntlBreakIterator::createWordInstance — Create break iterator for word breaks
This function is currently not documented; only its argument list is available.
locale
(PHP 5 >= 5.5.0, PHP 7)
IntlBreakIterator::current — Get index of current position
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7)
IntlBreakIterator::first — Set position to the first character in the text
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7)
IntlBreakIterator::following — Advance the iterator to the first boundary following specified offset
$offset
) : int
This function is currently not documented; only its argument list is available.
offset
(PHP 5 >= 5.5.0, PHP 7)
IntlBreakIterator::getErrorCode -- intl_get_error_code — Get last error code on the object
Object oriented style (method):
Procedural style:
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7)
IntlBreakIterator::getErrorMessage -- intl_get_error_message — Get last error message on the object
Object oriented style (method):
Procedural style:
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7)
IntlBreakIterator::getLocale — Get the locale associated with the object
$locale_type
) : string
This function is currently not documented; only its argument list is available.
locale_type
(PHP 5 >= 5.5.0, PHP 7)
IntlBreakIterator::getPartsIterator — Create iterator for navigating fragments between boundaries
$key_type = IntlPartsIterator::KEY_SEQUENTIAL
] ) : IntlPartsIterator
This function is currently not documented; only its argument list is available.
key_typeOptional key type. Possible values are:
IntlPartsIterator::KEY_SEQUENTIAL
- The default. Sequentially increasing integers used as key.
IntlPartsIterator::KEY_LEFT
- Byte offset left of current part used as key.
IntlPartsIterator::KEY_RIGHT
- Byte offset right of current part used as key.
(PHP 5 >= 5.5.0, PHP 7)
IntlBreakIterator::getText — Get the text being scanned
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7)
IntlBreakIterator::isBoundary — Tell whether an offset is a boundaryʼs offset
$offset
) : bool
This function is currently not documented; only its argument list is available.
offset
(PHP 5 >= 5.5.0, PHP 7)
IntlBreakIterator::last — Set the iterator position to index beyond the last character
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7)
IntlBreakIterator::next — Advance the iterator the next boundary
$offset
] ) : int
This function is currently not documented; only its argument list is available.
offset
(PHP 5 >= 5.5.0, PHP 7)
IntlBreakIterator::preceding — Set the iterator position to the first boundary before an offset
$offset
) : int
This function is currently not documented; only its argument list is available.
offset
(PHP 5 >= 5.5.0, PHP 7)
IntlBreakIterator::previous — Set the iterator position to the boundary immediately before the current
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7)
IntlBreakIterator::setText — Set the text being scanned
$text
) : bool
This function is currently not documented; only its argument list is available.
text
(PHP 5 >= 5.5.0, PHP 7)
A subclass of IntlBreakIterator that encapsulates ICU break iterators whose behavior is specified using a set of rules. This is the most common kind of break iterators.
These rules are described in the » ICU Boundary Analysis User Guide.
$key_type = IntlPartsIterator::KEY_SEQUENTIAL
] ) : IntlPartsIterator(PHP 5 >= 5.5.0, PHP 7)
IntlRuleBasedBreakIterator::__construct — Create iterator from ruleset
$rules
[, string $areCompiled
] )
This function is currently not documented; only its argument list is available.
rules
areCompiled
(PHP 5 >= 5.5.0, PHP 7)
IntlRuleBasedBreakIterator::getBinaryRules — Get the binary form of compiled rules
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7)
IntlRuleBasedBreakIterator::getRules — Get the rule set used to create this object
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7)
IntlRuleBasedBreakIterator::getRuleStatus — Get the largest status value from the break rules that determined the current break position
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7)
IntlRuleBasedBreakIterator::getRuleStatusVec — Get the status values from the break rules that determined the current break position
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7)
This break iterator identifies the boundaries between UTF-8 code points.
$key_type = IntlPartsIterator::KEY_SEQUENTIAL
] ) : IntlPartsIterator(PHP 5 >= 5.5.0, PHP 7)
IntlCodePointBreakIterator::getLastCodePoint — Get last code point passed over after advancing or receding the iterator
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7)
Objects of this class can be obtained from IntlBreakIterator objects. While the break iterators provide a sequence of boundary positions when iterated, IntlPartsIterator objects provide, as a convenience, the text fragments comprehended between two successive boundaries.
The keys may represent the offset of the left boundary, right boundary, or they may just the sequence of non-negative integers. See IntlBreakIterator::getPartsIterator().
IntlPartsIterator::KEY_SEQUENTIALIntlPartsIterator::KEY_LEFTIntlPartsIterator::KEY_RIGHT(PHP 5 >= 5.5.0, PHP 7)
IntlPartsIterator::getBreakIterator — Get IntlBreakIterator backing this parts iterator
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
$str
, string $toEncoding
, string $fromEncoding
[, array $options
] ) : stringUConverter::REASON_UNASSIGNEDUConverter::REASON_ILLEGALUConverter::REASON_IRREGULARUConverter::REASON_RESETUConverter::REASON_CLOSEUConverter::REASON_CLONEUConverter::UNSUPPORTED_CONVERTERUConverter::SBCSUConverter::DBCSUConverter::MBCSUConverter::LATIN_1UConverter::UTF8UConverter::UTF16_BigEndianUConverter::UTF16_LittleEndianUConverter::UTF32_BigEndianUConverter::UTF32_LittleEndianUConverter::EBCDIC_STATEFULUConverter::ISO_2022UConverter::LMBCS_1UConverter::LMBCS_2UConverter::LMBCS_3UConverter::LMBCS_4UConverter::LMBCS_5UConverter::LMBCS_6UConverter::LMBCS_8UConverter::LMBCS_11UConverter::LMBCS_16UConverter::LMBCS_17UConverter::LMBCS_18UConverter::LMBCS_19UConverter::LMBCS_LASTUConverter::HZUConverter::SCSUUConverter::ISCIIUConverter::US_ASCIIUConverter::UTF7UConverter::BOCU1UConverter::UTF16UConverter::UTF32UConverter::CESU8UConverter::IMAP_MAILBOX(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
UConverter::__construct — Create UConverter object
$destination_encoding
[, string $source_encoding
]] )
This function is currently not documented; only its argument list is available.
destination_encoding
source_encoding
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
UConverter::convert — Convert string from one charset to another
$str
[, bool $reverse
] ) : string
This function is currently not documented; only its argument list is available.
str
reverse
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
UConverter::fromUCallback — Default "from" callback function
$reason
, string $source
, string $codePoint
, int &$error
) : mixed
This function is currently not documented; only its argument list is available.
reason
source
codePoint
error
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
UConverter::getAliases — Get the aliases of the given name
$name
) : array
This function is currently not documented; only its argument list is available.
name
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
UConverter::getAvailable — Get the available canonical converter names
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
UConverter::getDestinationEncoding — Get the destination encoding
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
UConverter::getDestinationType — Get the destination converter type
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
UConverter::getErrorCode -- intl_get_error_code — Get last error code on the object
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
UConverter::getErrorMessage — Get last error message on the object
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
UConverter::getSourceEncoding — Get the source encoding
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
UConverter::getSourceType — Get the source converter type
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
UConverter::getStandards — Get standards associated to converter names
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
UConverter::getSubstChars — Get substitution chars
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
UConverter::reasonText — Get string representation of the callback reason
$reason
] ) : string
This function is currently not documented; only its argument list is available.
reason
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
UConverter::setDestinationEncoding — Set the destination encoding
$encoding
) : void
This function is currently not documented; only its argument list is available.
encoding
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
UConverter::setSourceEncoding — Set the source encoding
$encoding
) : void
This function is currently not documented; only its argument list is available.
encoding
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
UConverter::setSubstChars — Set the substitution chars
$chars
) : void
This function is currently not documented; only its argument list is available.
chars
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
UConverter::toUCallback — Default "to" callback function
$reason
, string $source
, string $codeUnits
, int &$error
) : mixed
This function is currently not documented; only its argument list is available.
reason
source
codeUnits
error
(PHP 5 >= 5.5.0, PHP 7, PECL >= 3.0.0a1)
UConverter::transcode — Convert string from one charset to another
$str
, string $toEncoding
, string $fromEncoding
[, array $options
] ) : string
This function is currently not documented; only its argument list is available.
str
toEncoding
fromEncoding
options
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
grapheme_extract — Function to extract a sequence of default grapheme clusters from a text buffer, which must be encoded in UTF-8
Procedural style
$haystack
, int $size
[, int $extract_type
[, int $start = 0
[, int &$next
]]] ) : stringFunction to extract a sequence of default grapheme clusters from a text buffer, which must be encoded in UTF-8.
haystackString to search.
sizeMaximum number items - based on the $extract_type - to return.
extract_typeDefines the type of units referred to by the $size parameter:
startStarting position in $haystack in bytes - if given, it must be zero or a positive value that is less than or equal to the length of $haystack in bytes, or a negative value that counts from the end of $haystack. If $start does not point to the first byte of a UTF-8 character, the start position is moved to the next character boundary.
nextReference to a value that will be set to the next starting position. When the call returns, this may point to the first byte position past the end of the string.
A string starting at offset $start and ending on a default grapheme cluster boundary that conforms to the $size and $extract_type specified.
| Version | Description |
|---|---|
| 7.1.0 |
Support for negative starts has been added.
|
Example #1 grapheme_extract() example
<?php
$char_a_ring_nfd = "a\xCC\x8A"; // 'LATIN SMALL LETTER A WITH RING ABOVE' (U+00E5) normalization form "D"
$char_o_diaeresis_nfd = "o\xCC\x88"; // 'LATIN SMALL LETTER O WITH DIAERESIS' (U+00F6) normalization form "D"
print urlencode(grapheme_extract( $char_a_ring_nfd . $char_o_diaeresis_nfd, 1, GRAPHEME_EXTR_COUNT, 2));
?>
The above example will output:
o%CC%88
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
grapheme_stripos — Find position (in grapheme units) of first occurrence of a case-insensitive string
Procedural style
$haystack
, string $needle
[, int $offset = 0
] ) : intFind position (in grapheme units) of first occurrence of a case-insensitive string
haystackThe string to look in. Must be valid UTF-8.
needleThe string to look for. Must be valid UTF-8.
offsetThe optional $offset parameter allows you to specify where in haystack to start searching as an offset in grapheme units (not bytes or characters). If the offset is negative, it is treated relative to the end of the string. The position returned is still relative to the beginning of haystack regardless of the value of $offset.
Returns the position as an integer. If needle is not found, grapheme_stripos() will return boolean FALSE.
| Version | Description |
|---|---|
| 7.1.0 |
Support for negative offsets has been added.
|
Example #1 grapheme_stripos() example
<?php
$char_a_ring_nfd = "a\xCC\x8A"; // 'LATIN SMALL LETTER A WITH RING ABOVE' (U+00E5) normalization form "D"
$char_o_diaeresis_nfd = "o\xCC\x88"; // 'LATIN SMALL LETTER O WITH DIAERESIS' (U+00F6) normalization form "D"
$char_O_diaeresis_nfd = "O\xCC\x88"; // 'LATIN CAPITAL LETTER O WITH DIAERESIS' (U+00D6) normalization form "D"
print grapheme_stripos( $char_a_ring_nfd . $char_a_ring_nfd . $char_o_diaeresis_nfd, $char_O_diaeresis_nfd);
?>
The above example will output:
2
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
grapheme_stristr — Returns part of haystack string from the first occurrence of case-insensitive needle to the end of haystack
Procedural style
$haystack
, string $needle
[, bool $before_needle = FALSE
] ) : stringReturns part of haystack string starting from and including the first occurrence of case-insensitive needle to the end of haystack.
haystackThe input string. Must be valid UTF-8.
needleThe string to look for. Must be valid UTF-8.
before_needle
If TRUE, grapheme_strstr() returns the part of the
haystack before the first occurrence of the needle (excluding needle).
Returns the portion of $haystack, or FALSE if $needle is not found.
Example #1 grapheme_stristr() example
<?php
$char_a_ring_nfd = "a\xCC\x8A"; // 'LATIN SMALL LETTER A WITH RING ABOVE' (U+00E5) normalization form "D"
$char_o_diaeresis_nfd = "o\xCC\x88"; // 'LATIN SMALL LETTER O WITH DIAERESIS' (U+00F6) normalization form "D"
$char_O_diaeresis_nfd = "O\xCC\x88"; // 'LATIN CAPITAL LETTER O WITH DIAERESIS' (U+00D6) normalization form "D"
print urlencode(grapheme_stristr( $char_a_ring_nfd . $char_o_diaeresis_nfd . $char_a_ring_nfd, $char_O_diaeresis_nfd));
?>
The above example will output:
o%CC%88a%CC%8A
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
grapheme_strlen — Get string length in grapheme units
Procedural style
$input
) : intGet string length in grapheme units (not bytes or characters)
inputThe string being measured for length. It must be a valid UTF-8 string.
The length of the string on success, and 0 if the string is empty.
Example #1 grapheme_strlen() example
<?php
$char_a_ring_nfd = "a\xCC\x8A"; // 'LATIN SMALL LETTER A WITH RING ABOVE' (U+00E5) normalization form "D"
$char_o_diaeresis_nfd = "o\xCC\x88"; // 'LATIN SMALL LETTER O WITH DIAERESIS' (U+00F6) normalization form "D"
print grapheme_strlen( 'abc' . $char_a_ring_nfd . $char_o_diaeresis_nfd . $char_a_ring_nfd);
?>
The above example will output:
6
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
grapheme_strpos — Find position (in grapheme units) of first occurrence of a string
Procedural style
$haystack
, string $needle
[, int $offset = 0
] ) : intFind position (in grapheme units) of first occurrence of a string
haystackThe string to look in. Must be valid UTF-8.
needleThe string to look for. Must be valid UTF-8.
offsetThe optional $offset parameter allows you to specify where in $haystack to start searching as an offset in grapheme units (not bytes or characters). If the offset is negative, it is treated relative to the end of the string. The position returned is still relative to the beginning of haystack regardless of the value of $offset.
Returns the position as an integer. If needle is not found, grapheme_strpos() will return boolean FALSE.
| Version | Description |
|---|---|
| 7.1.0 |
Support for negative offsets has been added.
|
Example #1 grapheme_strpos() example
<?php
$char_a_ring_nfd = "a\xCC\x8A"; // 'LATIN SMALL LETTER A WITH RING ABOVE' (U+00E5) normalization form "D"
$char_o_diaeresis_nfd = "o\xCC\x88"; // 'LATIN SMALL LETTER O WITH DIAERESIS' (U+00F6) normalization form "D"
print grapheme_strpos( $char_a_ring_nfd . $char_a_ring_nfd . $char_o_diaeresis_nfd, $char_o_diaeresis_nfd);
?>
The above example will output:
2
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
grapheme_strripos — Find position (in grapheme units) of last occurrence of a case-insensitive string
Procedural style
$haystack
, string $needle
[, int $offset = 0
] ) : intFind position (in grapheme units) of last occurrence of a case-insensitive string
haystackThe string to look in. Must be valid UTF-8.
needleThe string to look for. Must be valid UTF-8.
offsetThe optional $offset parameter allows you to specify where in $haystack to start searching as an offset in grapheme units (not bytes or characters). The position returned is still relative to the beginning of haystack regardless of the value of $offset.
Returns the position as an integer. If needle is not found, grapheme_strripos() will return boolean FALSE.
Example #1 grapheme_strripos() example
<?php
$char_a_ring_nfd = "a\xCC\x8A"; // 'LATIN SMALL LETTER A WITH RING ABOVE' (U+00E5) normalization form "D"
$char_o_diaeresis_nfd = "o\xCC\x88"; // 'LATIN SMALL LETTER O WITH DIAERESIS' (U+00F6) normalization form "D"
$char_O_diaeresis_nfd = "O\xCC\x88"; // 'LATIN CAPITAL LETTER O WITH DIAERESIS' (U+00D6) normalization form "D"
print grapheme_strripos( $char_a_ring_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, $char_O_diaeresis_nfd);
?>
The above example will output:
2
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
grapheme_strrpos — Find position (in grapheme units) of last occurrence of a string
Procedural style
$haystack
, string $needle
[, int $offset = 0
] ) : intFind position (in grapheme units) of last occurrence of a string
haystackThe string to look in. Must be valid UTF-8.
needleThe string to look for. Must be valid UTF-8.
offsetThe optional $offset parameter allows you to specify where in $haystack to start searching as an offset in grapheme units (not bytes or characters). The position returned is still relative to the beginning of haystack regardless of the value of $offset.
Returns the position as an integer. If needle is not found, grapheme_strrpos() will return boolean FALSE.
Example #1 grapheme_strrpos() example
<?php
$char_a_ring_nfd = "a\xCC\x8A"; // 'LATIN SMALL LETTER A WITH RING ABOVE' (U+00E5) normalization form "D"
$char_o_diaeresis_nfd = "o\xCC\x88"; // 'LATIN SMALL LETTER O WITH DIAERESIS' (U+00F6) normalization form "D"
print grapheme_strrpos( $char_a_ring_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, $char_o_diaeresis_nfd);
?>
The above example will output:
2
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
grapheme_strstr — Returns part of haystack string from the first occurrence of needle to the end of haystack
Procedural style
$haystack
, string $needle
[, bool $before_needle = FALSE
] ) : stringReturns part of haystack string from the first occurrence of needle to the end of haystack (including the needle).
haystackThe input string. Must be valid UTF-8.
needleThe string to look for. Must be valid UTF-8.
before_needle
If TRUE, grapheme_strstr() returns the part of the
haystack before the first occurrence of the needle (excluding the needle).
Returns the portion of string, or FALSE if needle is not found.
Example #1 grapheme_strstr() example
<?php
$char_a_ring_nfd = "a\xCC\x8A"; // 'LATIN SMALL LETTER A WITH RING ABOVE' (U+00E5) normalization form "D"
$char_o_diaeresis_nfd = "o\xCC\x88"; // 'LATIN SMALL LETTER O WITH DIAERESIS' (U+00F6) normalization form "D"
print urlencode(grapheme_stristr( $char_a_ring_nfd . $char_o_diaeresis_nfd . $char_a_ring_nfd, $char_o_diaeresis_nfd));
?>
The above example will output:
o%CC%88a%CC%8A
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
grapheme_substr — Return part of a string
Procedural style
$string
, int $start
[, int $length
] ) : stringReturn part of a string
stringThe input string. Must be valid UTF-8.
startStart position in default grapheme units. If $start is non-negative, the returned string will start at the $start'th position in $string, counting from zero. If $start is negative, the returned string will start at the $start'th grapheme unit from the end of string.
length
Length in grapheme units.
If $length is given and is positive, the string returned will contain
at most $length grapheme units beginning from $start (depending on the
length of string). If $length is given and is negative, then
that many grapheme units will be omitted from the end of string (after the
start position has been calculated when a start is negative). If $start
denotes a position beyond this truncation, FALSE will be returned.
Returns the extracted part of $string.
| Version | Description |
|---|---|
| 5.4 |
If length is given and positive and the
argument string is shorter than the specified length, all the rest of
the string according to start parameter is
returned. Previously, FALSE was returned.
|
Example #1 grapheme_substr() example
<?php
$char_a_ring_nfd = "a\xCC\x8A"; // 'LATIN SMALL LETTER A WITH RING ABOVE' (U+00E5) normalization form "D"
$char_o_diaeresis_nfd = "o\xCC\x88"; // 'LATIN SMALL LETTER O WITH DIAERESIS' (U+00F6) normalization form "D"
print urlencode(grapheme_substr( "ao" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O", 2, -1 ));
?>
The above example will output:
a%CC%8Abco%CC%88
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.2, PECL idn >= 0.1)
idn_to_ascii — Convert domain name to IDNA ASCII form
Procedural style
$domain
[, int $options = IDNA_DEFAULT
[, int $variant = INTL_IDNA_VARIANT_UTS46
[, array &$idna_info
]]] ) : stringThis function converts a Unicode domain name to an IDNA ASCII-compatible format.
domainThe domain to convert, which must be UTF-8 encoded.
optionsConversion options - combination of IDNA_* constants (except IDNA_ERROR_* constants).
variant
Either INTL_IDNA_VARIANT_2003 (deprecated as of PHP 7.2.0) for IDNA 2003 or
INTL_IDNA_VARIANT_UTS46 (only available as of ICU 4.6) for UTS #46.
idna_info
This parameter can be used only if
INTL_IDNA_VARIANT_UTS46 was used for
variant. In that case, it will be filled with an
array with the keys 'result', the possibly illegal
result of the transformation,
'isTransitionalDifferent', a boolean indicating
whether the usage of the transitional mechanisms of UTS #46 either has
or would have changed the result and 'errors',
which is an int representing a bitset of the error
constants IDNA_ERROR_*.
The domain name encoded in ASCII-compatible form, or FALSE on failure
| Version | Description |
|---|---|
| 7.4.0 |
The default value of variant is now
INTL_IDNA_VARIANT_UTS46 instead of the deprecated
INTL_IDNA_VARIANT_2003.
|
| 7.2.0 |
INTL_IDNA_VARIANT_2003 has been deprecated; use
INTL_IDNA_VARIANT_UTS46 instead.
|
| 5.4.0/PECL 2.0.0b1 |
Added the parameters variant and
idna_info; UTS #46 support (requires ICU ≥ 4.6).
|
Example #1 idn_to_ascii() example
<?php
echo idn_to_ascii('täst.de');
?>
The above example will output:
xn--tst-qla.de
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.2, PECL idn >= 0.1)
idn_to_utf8 — Convert domain name from IDNA ASCII to Unicode
Procedural style
$domain
[, int $options = IDNA_DEFAULT
[, int $variant = INTL_IDNA_VARIANT_UTS46
[, array &$idna_info
]]] ) : stringThis function converts a Unicode domain name from an IDNA ASCII-compatible format to plain Unicode, encoded in UTF-8.
domainDomain to convert in an IDNA ASCII-compatible format.
optionsConversion options - combination of IDNA_* constants (except IDNA_ERROR_* constants).
variant
Either INTL_IDNA_VARIANT_2003 (deprecated as of PHP 7.2.0) for IDNA 2003 or
INTL_IDNA_VARIANT_UTS46 (only available as of ICU 4.6) for UTS #46.
idna_info
This parameter can be used only if
INTL_IDNA_VARIANT_UTS46 was used for
variant. In that case, it will be filled with an
array with the keys 'result', the possibly illegal
result of the transformation,
'isTransitionalDifferent', a boolean indicating
whether the usage of the transitional mechanisms of UTS #46 either has
or would have changed the result and 'errors',
which is an int representing a bitset of the error
constants IDNA_ERROR_*.
The domain name in Unicode, encoded in UTF-8, or FALSE on failure
| Version | Description |
|---|---|
| 7.4.0 |
The default value of variant is now
INTL_IDNA_VARIANT_UTS46 instead of the deprecated
INTL_IDNA_VARIANT_2003.
|
| 7.2.0 |
INTL_IDNA_VARIANT_2003 has been deprecated; use
INTL_IDNA_VARIANT_UTS46 instead.
|
| 5.4.0/PECL 2.0.0b1 |
Added the parameters variant and
idna_info; UTS #46 support (requires ICU ≥ 4.6).
|
Example #1 idn_to_utf8() example
<?php
echo idn_to_utf8('xn--tst-qla.de');
?>
The above example will output:
täst.de
(PHP 7)
IntlChar provides access to a number of utility methods that can be used to access information about Unicode characters.
The methods and constants adhere closely to the names and behavior used by the underlying ICU library.
$characterName
[, int $nameChoice = IntlChar::UNICODE_CHAR_NAME
] ) : int$codepoint
[, int $nameChoice = IntlChar::UNICODE_CHAR_NAME
] ) : string$start
, mixed $limit
, callable $callback
[, int $nameChoice = IntlChar::UNICODE_CHAR_NAME
] ) : void$property
[, int $nameChoice = IntlChar::LONG_PROPERTY_NAME
] ) : string$property
, int $value
[, int $nameChoice = IntlChar::LONG_PROPERTY_NAME
] ) : stringIntlChar::UNICODE_VERSIONIntlChar::CODEPOINT_MINIntlChar::CODEPOINT_MAXIntlChar::NO_NUMERIC_VALUESpecial value that is returned by IntlChar::getNumericValue() when no numeric value is defined for a code point.
IntlChar::PROPERTY_ALPHABETICIntlChar::PROPERTY_BINARY_STARTIntlChar::PROPERTY_ASCII_HEX_DIGITIntlChar::PROPERTY_BIDI_CONTROLIntlChar::PROPERTY_BIDI_MIRROREDIntlChar::PROPERTY_DASHIntlChar::PROPERTY_DEFAULT_IGNORABLE_CODE_POINTIntlChar::PROPERTY_DEPRECATEDIntlChar::PROPERTY_DIACRITICIntlChar::PROPERTY_EXTENDERIntlChar::PROPERTY_FULL_COMPOSITION_EXCLUSIONIntlChar::PROPERTY_GRAPHEME_BASEIntlChar::PROPERTY_GRAPHEME_EXTENDIntlChar::PROPERTY_GRAPHEME_LINKIntlChar::PROPERTY_HEX_DIGITIntlChar::PROPERTY_HYPHENIntlChar::PROPERTY_ID_CONTINUEIntlChar::PROPERTY_ID_STARTIntlChar::PROPERTY_IDEOGRAPHICIntlChar::PROPERTY_IDS_BINARY_OPERATORIntlChar::PROPERTY_IDS_TRINARY_OPERATORIntlChar::PROPERTY_JOIN_CONTROLIntlChar::PROPERTY_LOGICAL_ORDER_EXCEPTIONIntlChar::PROPERTY_LOWERCASEIntlChar::PROPERTY_MATHIntlChar::PROPERTY_NONCHARACTER_CODE_POINTIntlChar::PROPERTY_QUOTATION_MARKIntlChar::PROPERTY_RADICALIntlChar::PROPERTY_SOFT_DOTTEDIntlChar::PROPERTY_TERMINAL_PUNCTUATIONIntlChar::PROPERTY_UNIFIED_IDEOGRAPHIntlChar::PROPERTY_UPPERCASEIntlChar::PROPERTY_WHITE_SPACEIntlChar::PROPERTY_XID_CONTINUEIntlChar::PROPERTY_XID_STARTIntlChar::PROPERTY_CASE_SENSITIVEIntlChar::PROPERTY_S_TERMIntlChar::PROPERTY_VARIATION_SELECTORIntlChar::PROPERTY_NFD_INERTIntlChar::PROPERTY_NFKD_INERTIntlChar::PROPERTY_NFC_INERTIntlChar::PROPERTY_NFKC_INERTIntlChar::PROPERTY_SEGMENT_STARTERIntlChar::PROPERTY_PATTERN_SYNTAXIntlChar::PROPERTY_PATTERN_WHITE_SPACEIntlChar::PROPERTY_POSIX_ALNUMIntlChar::PROPERTY_POSIX_BLANKIntlChar::PROPERTY_POSIX_GRAPHIntlChar::PROPERTY_POSIX_PRINTIntlChar::PROPERTY_POSIX_XDIGITIntlChar::PROPERTY_CASEDIntlChar::PROPERTY_CASE_IGNORABLEIntlChar::PROPERTY_CHANGES_WHEN_LOWERCASEDIntlChar::PROPERTY_CHANGES_WHEN_UPPERCASEDIntlChar::PROPERTY_CHANGES_WHEN_TITLECASEDIntlChar::PROPERTY_CHANGES_WHEN_CASEFOLDEDIntlChar::PROPERTY_CHANGES_WHEN_CASEMAPPEDIntlChar::PROPERTY_CHANGES_WHEN_NFKC_CASEFOLDEDIntlChar::PROPERTY_BINARY_LIMITIntlChar::PROPERTY_BIDI_CLASSIntlChar::PROPERTY_INT_STARTIntlChar::PROPERTY_BLOCKIntlChar::PROPERTY_CANONICAL_COMBINING_CLASSIntlChar::PROPERTY_DECOMPOSITION_TYPEIntlChar::PROPERTY_EAST_ASIAN_WIDTHIntlChar::PROPERTY_GENERAL_CATEGORYIntlChar::PROPERTY_JOINING_GROUPIntlChar::PROPERTY_JOINING_TYPEIntlChar::PROPERTY_LINE_BREAKIntlChar::PROPERTY_NUMERIC_TYPEIntlChar::PROPERTY_SCRIPTIntlChar::PROPERTY_HANGUL_SYLLABLE_TYPEIntlChar::PROPERTY_NFD_QUICK_CHECKIntlChar::PROPERTY_NFKD_QUICK_CHECKIntlChar::PROPERTY_NFC_QUICK_CHECKIntlChar::PROPERTY_NFKC_QUICK_CHECKIntlChar::PROPERTY_LEAD_CANONICAL_COMBINING_CLASSIntlChar::PROPERTY_TRAIL_CANONICAL_COMBINING_CLASSIntlChar::PROPERTY_GRAPHEME_CLUSTER_BREAKIntlChar::PROPERTY_SENTENCE_BREAKIntlChar::PROPERTY_WORD_BREAKIntlChar::PROPERTY_BIDI_PAIRED_BRACKET_TYPEIntlChar::PROPERTY_INT_LIMITIntlChar::PROPERTY_GENERAL_CATEGORY_MASKIntlChar::PROPERTY_MASK_STARTIntlChar::PROPERTY_MASK_LIMITIntlChar::PROPERTY_NUMERIC_VALUEIntlChar::PROPERTY_DOUBLE_STARTIntlChar::PROPERTY_DOUBLE_LIMITIntlChar::PROPERTY_AGEIntlChar::PROPERTY_STRING_STARTIntlChar::PROPERTY_BIDI_MIRRORING_GLYPHIntlChar::PROPERTY_CASE_FOLDINGIntlChar::PROPERTY_ISO_COMMENTIntlChar::PROPERTY_LOWERCASE_MAPPINGIntlChar::PROPERTY_NAMEIntlChar::PROPERTY_SIMPLE_CASE_FOLDINGIntlChar::PROPERTY_SIMPLE_LOWERCASE_MAPPINGIntlChar::PROPERTY_SIMPLE_TITLECASE_MAPPINGIntlChar::PROPERTY_SIMPLE_UPPERCASE_MAPPINGIntlChar::PROPERTY_TITLECASE_MAPPINGIntlChar::PROPERTY_UNICODE_1_NAMEIntlChar::PROPERTY_UPPERCASE_MAPPINGIntlChar::PROPERTY_BIDI_PAIRED_BRACKETIntlChar::PROPERTY_STRING_LIMITIntlChar::PROPERTY_SCRIPT_EXTENSIONSIntlChar::PROPERTY_OTHER_PROPERTY_STARTIntlChar::PROPERTY_OTHER_PROPERTY_LIMITIntlChar::PROPERTY_INVALID_CODEIntlChar::CHAR_CATEGORY_UNASSIGNEDIntlChar::CHAR_CATEGORY_GENERAL_OTHER_TYPESIntlChar::CHAR_CATEGORY_UPPERCASE_LETTERIntlChar::CHAR_CATEGORY_LOWERCASE_LETTERIntlChar::CHAR_CATEGORY_TITLECASE_LETTERIntlChar::CHAR_CATEGORY_MODIFIER_LETTERIntlChar::CHAR_CATEGORY_OTHER_LETTERIntlChar::CHAR_CATEGORY_NON_SPACING_MARKIntlChar::CHAR_CATEGORY_ENCLOSING_MARKIntlChar::CHAR_CATEGORY_COMBINING_SPACING_MARKIntlChar::CHAR_CATEGORY_DECIMAL_DIGIT_NUMBERIntlChar::CHAR_CATEGORY_LETTER_NUMBERIntlChar::CHAR_CATEGORY_OTHER_NUMBERIntlChar::CHAR_CATEGORY_SPACE_SEPARATORIntlChar::CHAR_CATEGORY_LINE_SEPARATORIntlChar::CHAR_CATEGORY_PARAGRAPH_SEPARATORIntlChar::CHAR_CATEGORY_CONTROL_CHARIntlChar::CHAR_CATEGORY_FORMAT_CHARIntlChar::CHAR_CATEGORY_PRIVATE_USE_CHARIntlChar::CHAR_CATEGORY_SURROGATEIntlChar::CHAR_CATEGORY_DASH_PUNCTUATIONIntlChar::CHAR_CATEGORY_START_PUNCTUATIONIntlChar::CHAR_CATEGORY_END_PUNCTUATIONIntlChar::CHAR_CATEGORY_CONNECTOR_PUNCTUATIONIntlChar::CHAR_CATEGORY_OTHER_PUNCTUATIONIntlChar::CHAR_CATEGORY_MATH_SYMBOLIntlChar::CHAR_CATEGORY_CURRENCY_SYMBOLIntlChar::CHAR_CATEGORY_MODIFIER_SYMBOLIntlChar::CHAR_CATEGORY_OTHER_SYMBOLIntlChar::CHAR_CATEGORY_INITIAL_PUNCTUATIONIntlChar::CHAR_CATEGORY_FINAL_PUNCTUATIONIntlChar::CHAR_CATEGORY_CHAR_CATEGORY_COUNTIntlChar::CHAR_DIRECTION_LEFT_TO_RIGHTIntlChar::CHAR_DIRECTION_RIGHT_TO_LEFTIntlChar::CHAR_DIRECTION_EUROPEAN_NUMBERIntlChar::CHAR_DIRECTION_EUROPEAN_NUMBER_SEPARATORIntlChar::CHAR_DIRECTION_EUROPEAN_NUMBER_TERMINATORIntlChar::CHAR_DIRECTION_ARABIC_NUMBERIntlChar::CHAR_DIRECTION_COMMON_NUMBER_SEPARATORIntlChar::CHAR_DIRECTION_BLOCK_SEPARATORIntlChar::CHAR_DIRECTION_SEGMENT_SEPARATORIntlChar::CHAR_DIRECTION_WHITE_SPACE_NEUTRALIntlChar::CHAR_DIRECTION_OTHER_NEUTRALIntlChar::CHAR_DIRECTION_LEFT_TO_RIGHT_EMBEDDINGIntlChar::CHAR_DIRECTION_LEFT_TO_RIGHT_OVERRIDEIntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT_ARABICIntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT_EMBEDDINGIntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT_OVERRIDEIntlChar::CHAR_DIRECTION_POP_DIRECTIONAL_FORMATIntlChar::CHAR_DIRECTION_DIR_NON_SPACING_MARKIntlChar::CHAR_DIRECTION_BOUNDARY_NEUTRALIntlChar::CHAR_DIRECTION_FIRST_STRONG_ISOLATEIntlChar::CHAR_DIRECTION_LEFT_TO_RIGHT_ISOLATEIntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT_ISOLATEIntlChar::CHAR_DIRECTION_POP_DIRECTIONAL_ISOLATEIntlChar::CHAR_DIRECTION_CHAR_DIRECTION_COUNTIntlChar::BLOCK_CODE_NO_BLOCKIntlChar::BLOCK_CODE_BASIC_LATINIntlChar::BLOCK_CODE_LATIN_1_SUPPLEMENTIntlChar::BLOCK_CODE_LATIN_EXTENDED_AIntlChar::BLOCK_CODE_LATIN_EXTENDED_BIntlChar::BLOCK_CODE_IPA_EXTENSIONSIntlChar::BLOCK_CODE_SPACING_MODIFIER_LETTERSIntlChar::BLOCK_CODE_COMBINING_DIACRITICAL_MARKSIntlChar::BLOCK_CODE_GREEKIntlChar::BLOCK_CODE_CYRILLICIntlChar::BLOCK_CODE_ARMENIANIntlChar::BLOCK_CODE_HEBREWIntlChar::BLOCK_CODE_ARABICIntlChar::BLOCK_CODE_SYRIACIntlChar::BLOCK_CODE_THAANAIntlChar::BLOCK_CODE_DEVANAGARIIntlChar::BLOCK_CODE_BENGALIIntlChar::BLOCK_CODE_GURMUKHIIntlChar::BLOCK_CODE_GUJARATIIntlChar::BLOCK_CODE_ORIYAIntlChar::BLOCK_CODE_TAMILIntlChar::BLOCK_CODE_TELUGUIntlChar::BLOCK_CODE_KANNADAIntlChar::BLOCK_CODE_MALAYALAMIntlChar::BLOCK_CODE_SINHALAIntlChar::BLOCK_CODE_THAIIntlChar::BLOCK_CODE_LAOIntlChar::BLOCK_CODE_TIBETANIntlChar::BLOCK_CODE_MYANMARIntlChar::BLOCK_CODE_GEORGIANIntlChar::BLOCK_CODE_HANGUL_JAMOIntlChar::BLOCK_CODE_ETHIOPICIntlChar::BLOCK_CODE_CHEROKEEIntlChar::BLOCK_CODE_UNIFIED_CANADIAN_ABORIGINAL_SYLLABICSIntlChar::BLOCK_CODE_OGHAMIntlChar::BLOCK_CODE_RUNICIntlChar::BLOCK_CODE_KHMERIntlChar::BLOCK_CODE_MONGOLIANIntlChar::BLOCK_CODE_LATIN_EXTENDED_ADDITIONALIntlChar::BLOCK_CODE_GREEK_EXTENDEDIntlChar::BLOCK_CODE_GENERAL_PUNCTUATIONIntlChar::BLOCK_CODE_SUPERSCRIPTS_AND_SUBSCRIPTSIntlChar::BLOCK_CODE_CURRENCY_SYMBOLSIntlChar::BLOCK_CODE_COMBINING_MARKS_FOR_SYMBOLSIntlChar::BLOCK_CODE_LETTERLIKE_SYMBOLSIntlChar::BLOCK_CODE_NUMBER_FORMSIntlChar::BLOCK_CODE_ARROWSIntlChar::BLOCK_CODE_MATHEMATICAL_OPERATORSIntlChar::BLOCK_CODE_MISCELLANEOUS_TECHNICALIntlChar::BLOCK_CODE_CONTROL_PICTURESIntlChar::BLOCK_CODE_OPTICAL_CHARACTER_RECOGNITIONIntlChar::BLOCK_CODE_ENCLOSED_ALPHANUMERICSIntlChar::BLOCK_CODE_BOX_DRAWINGIntlChar::BLOCK_CODE_BLOCK_ELEMENTSIntlChar::BLOCK_CODE_GEOMETRIC_SHAPESIntlChar::BLOCK_CODE_MISCELLANEOUS_SYMBOLSIntlChar::BLOCK_CODE_DINGBATSIntlChar::BLOCK_CODE_BRAILLE_PATTERNSIntlChar::BLOCK_CODE_CJK_RADICALS_SUPPLEMENTIntlChar::BLOCK_CODE_KANGXI_RADICALSIntlChar::BLOCK_CODE_IDEOGRAPHIC_DESCRIPTION_CHARACTERSIntlChar::BLOCK_CODE_CJK_SYMBOLS_AND_PUNCTUATIONIntlChar::BLOCK_CODE_HIRAGANAIntlChar::BLOCK_CODE_KATAKANAIntlChar::BLOCK_CODE_BOPOMOFOIntlChar::BLOCK_CODE_HANGUL_COMPATIBILITY_JAMOIntlChar::BLOCK_CODE_KANBUNIntlChar::BLOCK_CODE_BOPOMOFO_EXTENDEDIntlChar::BLOCK_CODE_ENCLOSED_CJK_LETTERS_AND_MONTHSIntlChar::BLOCK_CODE_CJK_COMPATIBILITYIntlChar::BLOCK_CODE_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_AIntlChar::BLOCK_CODE_CJK_UNIFIED_IDEOGRAPHSIntlChar::BLOCK_CODE_YI_SYLLABLESIntlChar::BLOCK_CODE_YI_RADICALSIntlChar::BLOCK_CODE_HANGUL_SYLLABLESIntlChar::BLOCK_CODE_HIGH_SURROGATESIntlChar::BLOCK_CODE_HIGH_PRIVATE_USE_SURROGATESIntlChar::BLOCK_CODE_LOW_SURROGATESIntlChar::BLOCK_CODE_PRIVATE_USE_AREAIntlChar::BLOCK_CODE_PRIVATE_USEIntlChar::BLOCK_CODE_CJK_COMPATIBILITY_IDEOGRAPHSIntlChar::BLOCK_CODE_ALPHABETIC_PRESENTATION_FORMSIntlChar::BLOCK_CODE_ARABIC_PRESENTATION_FORMS_AIntlChar::BLOCK_CODE_COMBINING_HALF_MARKSIntlChar::BLOCK_CODE_CJK_COMPATIBILITY_FORMSIntlChar::BLOCK_CODE_SMALL_FORM_VARIANTSIntlChar::BLOCK_CODE_ARABIC_PRESENTATION_FORMS_BIntlChar::BLOCK_CODE_SPECIALSIntlChar::BLOCK_CODE_HALFWIDTH_AND_FULLWIDTH_FORMSIntlChar::BLOCK_CODE_OLD_ITALICIntlChar::BLOCK_CODE_GOTHICIntlChar::BLOCK_CODE_DESERETIntlChar::BLOCK_CODE_BYZANTINE_MUSICAL_SYMBOLSIntlChar::BLOCK_CODE_MUSICAL_SYMBOLSIntlChar::BLOCK_CODE_MATHEMATICAL_ALPHANUMERIC_SYMBOLSIntlChar::BLOCK_CODE_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_BIntlChar::BLOCK_CODE_CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENTIntlChar::BLOCK_CODE_CYRILLIC_SUPPLEMENTIntlChar::BLOCK_CODE_CYRILLIC_SUPPLEMENTARYIntlChar::BLOCK_CODE_TAGALOGIntlChar::BLOCK_CODE_HANUNOOIntlChar::BLOCK_CODE_BUHIDIntlChar::BLOCK_CODE_TAGBANWAIntlChar::BLOCK_CODE_MISCELLANEOUS_MATHEMATICAL_SYMBOLS_AIntlChar::BLOCK_CODE_SUPPLEMENTAL_ARROWS_AIntlChar::BLOCK_CODE_SUPPLEMENTAL_ARROWS_BIntlChar::BLOCK_CODE_MISCELLANEOUS_MATHEMATICAL_SYMBOLS_BIntlChar::BLOCK_CODE_SUPPLEMENTAL_MATHEMATICAL_OPERATORSIntlChar::BLOCK_CODE_KATAKANA_PHONETIC_EXTENSIONSIntlChar::BLOCK_CODE_VARIATION_SELECTORSIntlChar::BLOCK_CODE_SUPPLEMENTARY_PRIVATE_USE_AREA_AIntlChar::BLOCK_CODE_SUPPLEMENTARY_PRIVATE_USE_AREA_BIntlChar::BLOCK_CODE_LIMBUIntlChar::BLOCK_CODE_TAI_LEIntlChar::BLOCK_CODE_KHMER_SYMBOLSIntlChar::BLOCK_CODE_PHONETIC_EXTENSIONSIntlChar::BLOCK_CODE_MISCELLANEOUS_SYMBOLS_AND_ARROWSIntlChar::BLOCK_CODE_YIJING_HEXAGRAM_SYMBOLSIntlChar::BLOCK_CODE_LINEAR_B_SYLLABARYIntlChar::BLOCK_CODE_LINEAR_B_IDEOGRAMSIntlChar::BLOCK_CODE_AEGEAN_NUMBERSIntlChar::BLOCK_CODE_UGARITICIntlChar::BLOCK_CODE_SHAVIANIntlChar::BLOCK_CODE_OSMANYAIntlChar::BLOCK_CODE_CYPRIOT_SYLLABARYIntlChar::BLOCK_CODE_TAI_XUAN_JING_SYMBOLSIntlChar::BLOCK_CODE_VARIATION_SELECTORS_SUPPLEMENTIntlChar::BLOCK_CODE_ANCIENT_GREEK_MUSICAL_NOTATIONIntlChar::BLOCK_CODE_ANCIENT_GREEK_NUMBERSIntlChar::BLOCK_CODE_ARABIC_SUPPLEMENTIntlChar::BLOCK_CODE_BUGINESEIntlChar::BLOCK_CODE_CJK_STROKESIntlChar::BLOCK_CODE_COMBINING_DIACRITICAL_MARKS_SUPPLEMENTIntlChar::BLOCK_CODE_COPTICIntlChar::BLOCK_CODE_ETHIOPIC_EXTENDEDIntlChar::BLOCK_CODE_ETHIOPIC_SUPPLEMENTIntlChar::BLOCK_CODE_GEORGIAN_SUPPLEMENTIntlChar::BLOCK_CODE_GLAGOLITICIntlChar::BLOCK_CODE_KHAROSHTHIIntlChar::BLOCK_CODE_MODIFIER_TONE_LETTERSIntlChar::BLOCK_CODE_NEW_TAI_LUEIntlChar::BLOCK_CODE_OLD_PERSIANIntlChar::BLOCK_CODE_PHONETIC_EXTENSIONS_SUPPLEMENTIntlChar::BLOCK_CODE_SUPPLEMENTAL_PUNCTUATIONIntlChar::BLOCK_CODE_SYLOTI_NAGRIIntlChar::BLOCK_CODE_TIFINAGHIntlChar::BLOCK_CODE_VERTICAL_FORMSIntlChar::BLOCK_CODE_NKOIntlChar::BLOCK_CODE_BALINESEIntlChar::BLOCK_CODE_LATIN_EXTENDED_CIntlChar::BLOCK_CODE_LATIN_EXTENDED_DIntlChar::BLOCK_CODE_PHAGS_PAIntlChar::BLOCK_CODE_PHOENICIANIntlChar::BLOCK_CODE_CUNEIFORMIntlChar::BLOCK_CODE_CUNEIFORM_NUMBERS_AND_PUNCTUATIONIntlChar::BLOCK_CODE_COUNTING_ROD_NUMERALSIntlChar::BLOCK_CODE_SUNDANESEIntlChar::BLOCK_CODE_LEPCHAIntlChar::BLOCK_CODE_OL_CHIKIIntlChar::BLOCK_CODE_CYRILLIC_EXTENDED_AIntlChar::BLOCK_CODE_VAIIntlChar::BLOCK_CODE_CYRILLIC_EXTENDED_BIntlChar::BLOCK_CODE_SAURASHTRAIntlChar::BLOCK_CODE_KAYAH_LIIntlChar::BLOCK_CODE_REJANGIntlChar::BLOCK_CODE_CHAMIntlChar::BLOCK_CODE_ANCIENT_SYMBOLSIntlChar::BLOCK_CODE_PHAISTOS_DISCIntlChar::BLOCK_CODE_LYCIANIntlChar::BLOCK_CODE_CARIANIntlChar::BLOCK_CODE_LYDIANIntlChar::BLOCK_CODE_MAHJONG_TILESIntlChar::BLOCK_CODE_DOMINO_TILESIntlChar::BLOCK_CODE_SAMARITANIntlChar::BLOCK_CODE_UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS_EXTENDEDIntlChar::BLOCK_CODE_TAI_THAMIntlChar::BLOCK_CODE_VEDIC_EXTENSIONSIntlChar::BLOCK_CODE_LISUIntlChar::BLOCK_CODE_BAMUMIntlChar::BLOCK_CODE_COMMON_INDIC_NUMBER_FORMSIntlChar::BLOCK_CODE_DEVANAGARI_EXTENDEDIntlChar::BLOCK_CODE_HANGUL_JAMO_EXTENDED_AIntlChar::BLOCK_CODE_JAVANESEIntlChar::BLOCK_CODE_MYANMAR_EXTENDED_AIntlChar::BLOCK_CODE_TAI_VIETIntlChar::BLOCK_CODE_MEETEI_MAYEKIntlChar::BLOCK_CODE_HANGUL_JAMO_EXTENDED_BIntlChar::BLOCK_CODE_IMPERIAL_ARAMAICIntlChar::BLOCK_CODE_OLD_SOUTH_ARABIANIntlChar::BLOCK_CODE_AVESTANIntlChar::BLOCK_CODE_INSCRIPTIONAL_PARTHIANIntlChar::BLOCK_CODE_INSCRIPTIONAL_PAHLAVIIntlChar::BLOCK_CODE_OLD_TURKICIntlChar::BLOCK_CODE_RUMI_NUMERAL_SYMBOLSIntlChar::BLOCK_CODE_KAITHIIntlChar::BLOCK_CODE_EGYPTIAN_HIEROGLYPHSIntlChar::BLOCK_CODE_ENCLOSED_ALPHANUMERIC_SUPPLEMENTIntlChar::BLOCK_CODE_ENCLOSED_IDEOGRAPHIC_SUPPLEMENTIntlChar::BLOCK_CODE_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_CIntlChar::BLOCK_CODE_MANDAICIntlChar::BLOCK_CODE_BATAKIntlChar::BLOCK_CODE_ETHIOPIC_EXTENDED_AIntlChar::BLOCK_CODE_BRAHMIIntlChar::BLOCK_CODE_BAMUM_SUPPLEMENTIntlChar::BLOCK_CODE_KANA_SUPPLEMENTIntlChar::BLOCK_CODE_PLAYING_CARDSIntlChar::BLOCK_CODE_MISCELLANEOUS_SYMBOLS_AND_PICTOGRAPHSIntlChar::BLOCK_CODE_EMOTICONSIntlChar::BLOCK_CODE_TRANSPORT_AND_MAP_SYMBOLSIntlChar::BLOCK_CODE_ALCHEMICAL_SYMBOLSIntlChar::BLOCK_CODE_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_DIntlChar::BLOCK_CODE_ARABIC_EXTENDED_AIntlChar::BLOCK_CODE_ARABIC_MATHEMATICAL_ALPHABETIC_SYMBOLSIntlChar::BLOCK_CODE_CHAKMAIntlChar::BLOCK_CODE_MEETEI_MAYEK_EXTENSIONSIntlChar::BLOCK_CODE_MEROITIC_CURSIVEIntlChar::BLOCK_CODE_MEROITIC_HIEROGLYPHSIntlChar::BLOCK_CODE_MIAOIntlChar::BLOCK_CODE_SHARADAIntlChar::BLOCK_CODE_SORA_SOMPENGIntlChar::BLOCK_CODE_SUNDANESE_SUPPLEMENTIntlChar::BLOCK_CODE_TAKRIIntlChar::BLOCK_CODE_COUNTIntlChar::BLOCK_CODE_INVALID_CODEIntlChar::BPT_NONEIntlChar::BPT_OPENIntlChar::BPT_CLOSEIntlChar::BPT_COUNTIntlChar::EA_NEUTRALIntlChar::EA_AMBIGUOUSIntlChar::EA_HALFWIDTHIntlChar::EA_FULLWIDTHIntlChar::EA_NARROWIntlChar::EA_WIDEIntlChar::EA_COUNTIntlChar::UNICODE_CHAR_NAMEIntlChar::UNICODE_10_CHAR_NAMEIntlChar::EXTENDED_CHAR_NAMEIntlChar::CHAR_NAME_ALIASIntlChar::CHAR_NAME_CHOICE_COUNTIntlChar::SHORT_PROPERTY_NAMEIntlChar::LONG_PROPERTY_NAMEIntlChar::PROPERTY_NAME_CHOICE_COUNTIntlChar::DT_NONEIntlChar::DT_CANONICALIntlChar::DT_COMPATIntlChar::DT_CIRCLEIntlChar::DT_FINALIntlChar::DT_FONTIntlChar::DT_FRACTIONIntlChar::DT_INITIALIntlChar::DT_ISOLATEDIntlChar::DT_MEDIALIntlChar::DT_NARROWIntlChar::DT_NOBREAKIntlChar::DT_SMALLIntlChar::DT_SQUAREIntlChar::DT_SUBIntlChar::DT_SUPERIntlChar::DT_VERTICALIntlChar::DT_WIDEIntlChar::DT_COUNTIntlChar::JT_NON_JOININGIntlChar::JT_JOIN_CAUSINGIntlChar::JT_DUAL_JOININGIntlChar::JT_LEFT_JOININGIntlChar::JT_RIGHT_JOININGIntlChar::JT_TRANSPARENTIntlChar::JT_COUNTIntlChar::JG_NO_JOINING_GROUPIntlChar::JG_AINIntlChar::JG_ALAPHIntlChar::JG_ALEFIntlChar::JG_BEHIntlChar::JG_BETHIntlChar::JG_DALIntlChar::JG_DALATH_RISHIntlChar::JG_EIntlChar::JG_FEHIntlChar::JG_FINAL_SEMKATHIntlChar::JG_GAFIntlChar::JG_GAMALIntlChar::JG_HAHIntlChar::JG_TEH_MARBUTA_GOALIntlChar::JG_HAMZA_ON_HEH_GOALIntlChar::JG_HEIntlChar::JG_HEHIntlChar::JG_HEH_GOALIntlChar::JG_HETHIntlChar::JG_KAFIntlChar::JG_KAPHIntlChar::JG_KNOTTED_HEHIntlChar::JG_LAMIntlChar::JG_LAMADHIntlChar::JG_MEEMIntlChar::JG_MIMIntlChar::JG_NOONIntlChar::JG_NUNIntlChar::JG_PEIntlChar::JG_QAFIntlChar::JG_QAPHIntlChar::JG_REHIntlChar::JG_REVERSED_PEIntlChar::JG_SADIntlChar::JG_SADHEIntlChar::JG_SEENIntlChar::JG_SEMKATHIntlChar::JG_SHINIntlChar::JG_SWASH_KAFIntlChar::JG_SYRIAC_WAWIntlChar::JG_TAHIntlChar::JG_TAWIntlChar::JG_TEH_MARBUTAIntlChar::JG_TETHIntlChar::JG_WAWIntlChar::JG_YEHIntlChar::JG_YEH_BARREEIntlChar::JG_YEH_WITH_TAILIntlChar::JG_YUDHIntlChar::JG_YUDH_HEIntlChar::JG_ZAINIntlChar::JG_FEIntlChar::JG_KHAPHIntlChar::JG_ZHAINIntlChar::JG_BURUSHASKI_YEH_BARREEIntlChar::JG_FARSI_YEHIntlChar::JG_NYAIntlChar::JG_ROHINGYA_YEHIntlChar::JG_COUNTIntlChar::GCB_OTHERIntlChar::GCB_CONTROLIntlChar::GCB_CRIntlChar::GCB_EXTENDIntlChar::GCB_LIntlChar::GCB_LFIntlChar::GCB_LVIntlChar::GCB_LVTIntlChar::GCB_TIntlChar::GCB_VIntlChar::GCB_SPACING_MARKIntlChar::GCB_PREPENDIntlChar::GCB_REGIONAL_INDICATORIntlChar::GCB_COUNTIntlChar::WB_OTHERIntlChar::WB_ALETTERIntlChar::WB_FORMATIntlChar::WB_KATAKANAIntlChar::WB_MIDLETTERIntlChar::WB_MIDNUMIntlChar::WB_NUMERICIntlChar::WB_EXTENDNUMLETIntlChar::WB_CRIntlChar::WB_EXTENDIntlChar::WB_LFIntlChar::WB_MIDNUMLETIntlChar::WB_NEWLINEIntlChar::WB_REGIONAL_INDICATORIntlChar::WB_HEBREW_LETTERIntlChar::WB_SINGLE_QUOTEIntlChar::WB_DOUBLE_QUOTEIntlChar::WB_COUNTIntlChar::SB_OTHERIntlChar::SB_ATERMIntlChar::SB_CLOSEIntlChar::SB_FORMATIntlChar::SB_LOWERIntlChar::SB_NUMERICIntlChar::SB_OLETTERIntlChar::SB_SEPIntlChar::SB_SPIntlChar::SB_STERMIntlChar::SB_UPPERIntlChar::SB_CRIntlChar::SB_EXTENDIntlChar::SB_LFIntlChar::SB_SCONTINUEIntlChar::SB_COUNTIntlChar::LB_UNKNOWNIntlChar::LB_AMBIGUOUSIntlChar::LB_ALPHABETICIntlChar::LB_BREAK_BOTHIntlChar::LB_BREAK_AFTERIntlChar::LB_BREAK_BEFOREIntlChar::LB_MANDATORY_BREAKIntlChar::LB_CONTINGENT_BREAKIntlChar::LB_CLOSE_PUNCTUATIONIntlChar::LB_COMBINING_MARKIntlChar::LB_CARRIAGE_RETURNIntlChar::LB_EXCLAMATIONIntlChar::LB_GLUEIntlChar::LB_HYPHENIntlChar::LB_IDEOGRAPHICIntlChar::LB_INSEPARABLEIntlChar::LB_INSEPERABLEIntlChar::LB_INFIX_NUMERICIntlChar::LB_LINE_FEEDIntlChar::LB_NONSTARTERIntlChar::LB_NUMERICIntlChar::LB_OPEN_PUNCTUATIONIntlChar::LB_POSTFIX_NUMERICIntlChar::LB_PREFIX_NUMERICIntlChar::LB_QUOTATIONIntlChar::LB_COMPLEX_CONTEXTIntlChar::LB_SURROGATEIntlChar::LB_SPACEIntlChar::LB_BREAK_SYMBOLSIntlChar::LB_ZWSPACEIntlChar::LB_NEXT_LINEIntlChar::LB_WORD_JOINERIntlChar::LB_H2IntlChar::LB_H3IntlChar::LB_JLIntlChar::LB_JTIntlChar::LB_JVIntlChar::LB_CLOSE_PARENTHESISIntlChar::LB_CONDITIONAL_JAPANESE_STARTERIntlChar::LB_HEBREW_LETTERIntlChar::LB_REGIONAL_INDICATORIntlChar::LB_COUNTIntlChar::NT_NONEIntlChar::NT_DECIMALIntlChar::NT_DIGITIntlChar::NT_NUMERICIntlChar::NT_COUNTIntlChar::HST_NOT_APPLICABLEIntlChar::HST_LEADING_JAMOIntlChar::HST_VOWEL_JAMOIntlChar::HST_TRAILING_JAMOIntlChar::HST_LV_SYLLABLEIntlChar::HST_LVT_SYLLABLEIntlChar::HST_COUNTIntlChar::FOLD_CASE_DEFAULTIntlChar::FOLD_CASE_EXCLUDE_SPECIAL_I
| Version | Description |
|---|---|
| 7.0.6 |
The IntlChar::NO_NUMERIC_VALUE constant was added.
|
(PHP 7)
IntlChar::charAge — Get the "age" of the code point
Gets the "age" of the code point.
The "age" is the Unicode version when the code point was first designated (as a non-character or for Private Use) or assigned a character. This can be useful to avoid emitting code points to receiving processes that do not accept newer characters.
The Unicode version number, as an array.
For example, version 1.3.31.2 would be represented as [1, 3, 31, 2].
Example #1 Testing different code points
<?php
var_dump(IntlChar::charage("\u{2603}"));
var_dump(IntlChar::charage("\u{1F576}"));
?>
The above example will output:
array(4) {
[0]=>
int(1)
[1]=>
int(1)
[2]=>
int(0)
[3]=>
int(0)
}
array(4) {
[0]=>
int(7)
[1]=>
int(0)
[2]=>
int(0)
[3]=>
int(0)
}
(PHP 7)
IntlChar::charDigitValue — Get the decimal digit value of a decimal digit character
Returns the decimal digit value of a decimal digit character.
Such characters have the general category "Nd" (decimal digit numbers) and a Numeric_Type of Decimal.
The decimal digit value of codepoint,
or -1 if it is not a decimal digit character.
Example #1 Testing different code points
<?php
var_dump(IntlChar::charDigitValue("1"));
var_dump(IntlChar::charDigitValue("\u{0662}"));
var_dump(IntlChar::charDigitValue("\u{0E53}"));
?>
The above example will output:
int(1) int(2) int(3)
(PHP 7)
IntlChar::charDirection — Get bidirectional category value for a code point
Returns the bidirectional category value for the code point, which is used in the » Unicode bidirectional algorithm (UAX #9).
Note:
Some unassigned code points have bidi values of R or AL because they are in blocks that are reserved for Right-To-Left scripts.
The bidirectional category value; one of the following constants:
IntlChar::CHAR_DIRECTION_LEFT_TO_RIGHTIntlChar::CHAR_DIRECTION_RIGHT_TO_LEFTIntlChar::CHAR_DIRECTION_EUROPEAN_NUMBERIntlChar::CHAR_DIRECTION_EUROPEAN_NUMBER_SEPARATORIntlChar::CHAR_DIRECTION_EUROPEAN_NUMBER_TERMINATORIntlChar::CHAR_DIRECTION_ARABIC_NUMBERIntlChar::CHAR_DIRECTION_COMMON_NUMBER_SEPARATORIntlChar::CHAR_DIRECTION_BLOCK_SEPARATORIntlChar::CHAR_DIRECTION_SEGMENT_SEPARATORIntlChar::CHAR_DIRECTION_WHITE_SPACE_NEUTRALIntlChar::CHAR_DIRECTION_OTHER_NEUTRALIntlChar::CHAR_DIRECTION_LEFT_TO_RIGHT_EMBEDDINGIntlChar::CHAR_DIRECTION_LEFT_TO_RIGHT_OVERRIDEIntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT_ARABICIntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT_EMBEDDINGIntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT_OVERRIDEIntlChar::CHAR_DIRECTION_POP_DIRECTIONAL_FORMATIntlChar::CHAR_DIRECTION_DIR_NON_SPACING_MARKIntlChar::CHAR_DIRECTION_BOUNDARY_NEUTRALIntlChar::CHAR_DIRECTION_FIRST_STRONG_ISOLATEIntlChar::CHAR_DIRECTION_LEFT_TO_RIGHT_ISOLATEIntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT_ISOLATEIntlChar::CHAR_DIRECTION_POP_DIRECTIONAL_ISOLATEIntlChar::CHAR_DIRECTION_CHAR_DIRECTION_COUNTExample #1 Testing different code points
<?php
var_dump(IntlChar::charDirection("A") === IntlChar::CHAR_DIRECTION_LEFT_TO_RIGHT);
var_dump(IntlChar::charDirection("\u{05E9}") === IntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT);
var_dump(IntlChar::charDirection("+") === IntlChar::CHAR_DIRECTION_EUROPEAN_NUMBER_SEPARATOR);
var_dump(IntlChar::charDirection(".") === IntlChar::CHAR_DIRECTION_COMMON_NUMBER_SEPARATOR);
?>
The above example will output:
bool(true) bool(true) bool(true) bool(true)
(PHP 7)
IntlChar::charFromName — Find Unicode character by name and return its code point value
$characterName
[, int $nameChoice = IntlChar::UNICODE_CHAR_NAME
] ) : intFinds a Unicode character by its name and returns its code point value.
The name is matched exactly and completely. If the name does not correspond to a code point, NULL is returned.
A Unicode 1.0 name is matched only if it differs from the modern name. Unicode names are all uppercase. Extended names are lowercase followed by an uppercase hexadecimal number, and within angle brackets.
characterNameFull name of the Unicode character.
nameChoiceWhich set of names to use for the lookup. Can be any of these constants:
IntlChar::UNICODE_CHAR_NAME (default)IntlChar::UNICODE_10_CHAR_NAMEIntlChar::EXTENDED_CHAR_NAMEIntlChar::CHAR_NAME_ALIASIntlChar::CHAR_NAME_CHOICE_COUNT
The Unicode value of the code point with the given name (as an integer), or NULL if there is no such code point.
Example #1 Testing different code points
<?php
var_dump(IntlChar::charFromName("LATIN CAPITAL LETTER A"));
var_dump(IntlChar::charFromName("SNOWMAN"));
var_dump(IntlChar::charFromName("RECYCLING SYMBOL FOR TYPE-1 PLASTICS"));
var_dump(IntlChar::charFromName("A RANDOM STRING WHICH DOESN'T CORRESPOND TO ANY UNICODE CHARACTER"));
?>
The above example will output:
int(65) int(9731) int(9843) bool(false)
(PHP 7)
IntlChar::charMirror — Get the "mirror-image" character for a code point
Maps the specified character to a "mirror-image" character.
For characters with the Bidi_Mirrored property, implementations sometimes need a "poor man's" mapping to another Unicode character (code point) such that the default glyph may serve as the mirror-image of the default glyph of the specified character. This is useful for text conversion to and from codepages with visual order, and for displays without glyph selection capabilities.
Returns another Unicode code point that may serve as a mirror-image substitute, or codepoint
itself if there is no such mapping or codepoint does not have the
Bidi_Mirrored property.
The return type will be integer unless the code point was passed as a UTF-8 string, in which case a string will be returned.
Example #1 Testing different code points
<?php
var_dump(IntlChar::charMirror("A"));
var_dump(IntlChar::charMirror("<"));
var_dump(IntlChar::charMirror("("));
?>
The above example will output:
string(1) "A" string(1) ">" string(2) ")"
IntlChar::PROPERTY_BIDI_MIRRORED(PHP 7)
IntlChar::charName — Retrieve the name of a Unicode character
$codepoint
[, int $nameChoice = IntlChar::UNICODE_CHAR_NAME
] ) : stringRetrieves the name of a Unicode character.
Depending on nameChoice, the resulting character name is the "modern" name or the name that
was defined in Unicode version 1.0. The name contains only "invariant" characters like A-Z, 0-9, space, and '-'.
Unicode 1.0 names are only retrieved if they are different from the modern names and if ICU contains the data for them.
codepointThe integer codepoint value (e.g. 0x2603 for U+2603 SNOWMAN), or the character encoded as a UTF-8 string (e.g. "\u{2603}")
nameChoiceWhich set of names to use for the lookup. Can be any of these constants:
IntlChar::UNICODE_CHAR_NAME (default)IntlChar::UNICODE_10_CHAR_NAMEIntlChar::EXTENDED_CHAR_NAMEIntlChar::CHAR_NAME_ALIASIntlChar::CHAR_NAME_CHOICE_COUNT
The corresponding name, or an empty string if there is no name for this character,
or NULL if there is no such code point.
Example #1 Testing different code points
<?php
var_dump(IntlChar::charName("."));
var_dump(IntlChar::charName(".", IntlChar::UNICODE_CHAR_NAME));
var_dump(IntlChar::charName("\u{2603}"));
var_dump(IntlChar::charName("\u{0000}"));
?>
The above example will output:
string(9) "FULL STOP" string(9) "FULL STOP" string(7) "SNOWMAN" string(0) ""
(PHP 7)
IntlChar::charType — Get the general category value for a code point
Returns the general category value for the code point.
Returns the general category type, which may be one of the following constants:
IntlChar::CHAR_CATEGORY_UNASSIGNEDIntlChar::CHAR_CATEGORY_GENERAL_OTHER_TYPESIntlChar::CHAR_CATEGORY_UPPERCASE_LETTERIntlChar::CHAR_CATEGORY_LOWERCASE_LETTERIntlChar::CHAR_CATEGORY_TITLECASE_LETTERIntlChar::CHAR_CATEGORY_MODIFIER_LETTERIntlChar::CHAR_CATEGORY_OTHER_LETTERIntlChar::CHAR_CATEGORY_NON_SPACING_MARKIntlChar::CHAR_CATEGORY_ENCLOSING_MARKIntlChar::CHAR_CATEGORY_COMBINING_SPACING_MARKIntlChar::CHAR_CATEGORY_DECIMAL_DIGIT_NUMBERIntlChar::CHAR_CATEGORY_LETTER_NUMBERIntlChar::CHAR_CATEGORY_OTHER_NUMBERIntlChar::CHAR_CATEGORY_SPACE_SEPARATORIntlChar::CHAR_CATEGORY_LINE_SEPARATORIntlChar::CHAR_CATEGORY_PARAGRAPH_SEPARATORIntlChar::CHAR_CATEGORY_CONTROL_CHARIntlChar::CHAR_CATEGORY_FORMAT_CHARIntlChar::CHAR_CATEGORY_PRIVATE_USE_CHARIntlChar::CHAR_CATEGORY_SURROGATEIntlChar::CHAR_CATEGORY_DASH_PUNCTUATIONIntlChar::CHAR_CATEGORY_START_PUNCTUATIONIntlChar::CHAR_CATEGORY_END_PUNCTUATIONIntlChar::CHAR_CATEGORY_CONNECTOR_PUNCTUATIONIntlChar::CHAR_CATEGORY_OTHER_PUNCTUATIONIntlChar::CHAR_CATEGORY_MATH_SYMBOLIntlChar::CHAR_CATEGORY_CURRENCY_SYMBOLIntlChar::CHAR_CATEGORY_MODIFIER_SYMBOLIntlChar::CHAR_CATEGORY_OTHER_SYMBOLIntlChar::CHAR_CATEGORY_INITIAL_PUNCTUATIONIntlChar::CHAR_CATEGORY_FINAL_PUNCTUATIONIntlChar::CHAR_CATEGORY_CHAR_CATEGORY_COUNTExample #1 Testing different code points
<?php
var_dump(IntlChar::charType("A") === IntlChar::CHAR_CATEGORY_UPPERCASE_LETTER);
var_dump(IntlChar::charType(".") === IntlChar::CHAR_CATEGORY_OTHER_PUNCTUATION);
var_dump(IntlChar::charType("\t") === IntlChar::CHAR_CATEGORY_CONTROL_CHAR);
var_dump(IntlChar::charType("\u{2603}") === IntlChar::CHAR_CATEGORY_OTHER_SYMBOL);
?>
The above example will output:
bool(true) bool(true) bool(true) bool(true)
(PHP 7)
IntlChar::chr — Return Unicode character by code point value
Returns a string containing the character specified by the Unicode code point value.
This function compliments IntlChar::ord().
A string containing the single character specified by the Unicode code point value.
Example #1 Testing different code points
<?php
$values = ["A", 63, 123, 9731];
foreach ($values as $value) {
var_dump(IntlChar::chr($value));
}
?>
The above example will output:
string(1) "A"
string(1) "?"
string(1) "{"
string(3) "☃"
(PHP 7)
IntlChar::digit — Get the decimal digit value of a code point for a given radix
$codepoint
[, int $radix = 10
] ) : intReturns the decimal digit value of the code point in the specified radix.
If the radix is not in the range 2<=radix<=36 or if the value of codepoint
is not a valid digit in the specified radix, FALSE is returned.
A character is a valid digit if at least one of the following is true:
Returns the numeric value represented by the character in the specified radix,
or FALSE if there is no value or if the value exceeds the radix.
This function may
return Boolean FALSE, but may also return a non-Boolean value which
evaluates to FALSE. Please read the section on Booleans for more
information. Use the ===
operator for testing the return value of this
function.
Example #1 Testing different code points
<?php
var_dump(IntlChar::digit("0"));
var_dump(IntlChar::digit("3"));
var_dump(IntlChar::digit("A"));
var_dump(IntlChar::digit("A", 16));
?>
The above example will output:
int(0) int(3) bool(false) int(10)
IntlChar::PROPERTY_NUMERIC_TYPE(PHP 7)
IntlChar::enumCharNames — Enumerate all assigned Unicode characters within a range
$start
, mixed $limit
, callable $callback
[, int $nameChoice = IntlChar::UNICODE_CHAR_NAME
] ) : voidEnumerate all assigned Unicode characters between the start and limit code points (start inclusive, limit exclusive) and call a function for each, passing the code point value and the character name.
For Unicode 1.0 names, only those are enumerated that differ from the modern names.
startThe first code point in the enumeration range.
limitOne more than the last code point in the enumeration range (the first one after the range).
callbackThe function that is to be called for each character name. The following three arguments will be passed into it:
nameChoiceSelector for which kind of names to enumerate. Can be any of these constants:
IntlChar::UNICODE_CHAR_NAME (default)IntlChar::UNICODE_10_CHAR_NAMEIntlChar::EXTENDED_CHAR_NAMEIntlChar::CHAR_NAME_ALIASIntlChar::CHAR_NAME_CHOICE_COUNTNo value is returned.
Example #1 Enumerating over a sample range of code points
<?php
IntlChar::enumCharNames(0x2600, 0x2610, function($codepoint, $nameChoice, $name) {
printf("U+%04x %s\n", $codepoint, $name);
});
?>
The above example will output:
U+2600 BLACK SUN WITH RAYS U+2601 CLOUD U+2602 UMBRELLA U+2603 SNOWMAN U+2604 COMET U+2605 BLACK STAR U+2606 WHITE STAR U+2607 LIGHTNING U+2608 THUNDERSTORM U+2609 SUN U+260a ASCENDING NODE U+260b DESCENDING NODE U+260c CONJUNCTION U+260d OPPOSITION U+260e BLACK TELEPHONE U+260f WHITE TELEPHONE
(PHP 7)
IntlChar::enumCharTypes — Enumerate all code points with their Unicode general categories
Enumerates efficiently all code points with their Unicode general categories. This is useful for building data structures, for enumerating all assigned code points, etc.
For each contiguous range of code points with a given general category ("character type"), the
callback function is called. Adjacent ranges have different types. The Unicode Standard
guarantees that the numeric value of the type is 0..31.
callbackThe function that is to be called for each contiguous range of code points with the same general category. The following three arguments will be passed into it:
No value is returned.
Example #1 Enumerating over a sample range of code points
<?php
IntlChar::enumCharTypes(function($start, $end, $type) {
printf("U+%04x through U+%04x are in category %d\n", $start, $end, $type);
});
?>
The above example will output:
U+0000 through U+0020 are in category 15 U+0020 through U+0021 are in category 12 U+0021 through U+0024 are in category 23 U+0024 through U+0025 are in category 25 U+0025 through U+0028 are in category 23 U+0028 through U+0029 are in category 20 U+0029 through U+002a are in category 21 U+002a through U+002b are in category 23 U+002b through U+002c are in category 24 U+002c through U+002d are in category 23 U+002d through U+002e are in category 19 U+002e through U+0030 are in category 23 U+0030 through U+003a are in category 9 ...
(PHP 7)
IntlChar::foldCase — Perform case folding on a code point
$codepoint
[, int $options = IntlChar::FOLD_CASE_DEFAULT
] ) : mixedThe given character is mapped to its case folding equivalent; if the character has no case folding equivalent, the character itself is returned.
Returns the Simple_Case_Folding of the code point, if any; otherwise the code point itself.
(PHP 7)
IntlChar::forDigit — Get character representation for a given digit and radix
$digit
[, int $radix = 10
] ) : intDetermines the character representation for a specific digit in the specified radix.
If the value of radix is not a valid radix, or the value of digit is not a valid digit in the specified radix,
the null character (U+0000) is returned.
The radix argument is valid if it is greater than or equal to 2 and less than or equal to 36.
The digit argument is valid if 0 <= digit < radix.
If the digit is less than 10, then '0' + digit is returned. Otherwise, the value 'a' + digit - 10 is returned.
digitThe number to convert to a character.
radix
The radix (defaults to 10).
The character representation (as a string) of the specified digit in the specified radix.
Example #1 Testing different code points
<?php
var_dump(IntlChar::forDigit(0));
var_dump(IntlChar::forDigit(3));
var_dump(IntlChar::forDigit(3, 10));
var_dump(IntlChar::forDigit(10));
var_dump(IntlChar::forDigit(10, 16));
?>
The above example will output:
int(48) int(51) int(51) int(0) int(97)
IntlChar::PROPERTY_NUMERIC_TYPE(PHP 7)
IntlChar::getBidiPairedBracket — Get the paired bracket character for a code point
Maps the specified character to its paired bracket character.
For Bidi_Paired_Bracket_Type!=None, this is the same as IntlChar::charMirror().
Otherwise codepoint itself is returned.
Returns the paired bracket code point, or codepoint itself if there is no such mapping.
The return type will be integer unless the code point was passed as a UTF-8 string, in which case a string will be returned.
Example #1 Testing different code points
<?php
var_dump(IntlChar::getBidiPairedBracket(91));
var_dump(IntlChar::getBidiPairedBracket('['));
?>
The above example will output:
int(93) string(1) "]"
IntlChar::PROPERTY_BIDI_PAIRED_BRACKETIntlChar::PROPERTY_BIDI_PAIRED_BRACKET_TYPE(PHP 7)
IntlChar::getBlockCode — Get the Unicode allocation block containing a code point
Returns the Unicode allocation block that contains the character.
Returns the block value for codepoint.
See the IntlChar::BLOCK_CODE_* constants for possible return values.
Example #1 Testing different code points
<?php
var_dump(IntlChar::getBlockCode("A") === IntlChar::BLOCK_CODE_BASIC_LATIN);
var_dump(IntlChar::getBlockCode("Φ") === IntlChar::BLOCK_CODE_GREEK);
var_dump(IntlChar::getBlockCode("\u{2603}") === IntlChar::BLOCK_CODE_MISCELLANEOUS_SYMBOLS);
?>
The above example will output:
bool(true) bool(true) bool(true)
(PHP 7)
IntlChar::getCombiningClass — Get the combining class of a code point
Returns the combining class of the code point.
Returns the combining class of the character.
Example #1 Testing different code points
<?php
var_dump(IntlChar::getCombiningClass("A"));
var_dump(IntlChar::getCombiningClass("\u{0334}"));
var_dump(IntlChar::getCombiningClass("\u{0358}"));
?>
The above example will output:
int(0) int(1) int(232)
(PHP 7)
IntlChar::getFC_NFKC_Closure — Get the FC_NFKC_Closure property for a code point
Gets the FC_NFKC_Closure property string for a character.
Returns the FC_NFKC_Closure property string for the codepoint, or an empty string if there is none.
Example #1 Testing different code points
<?php
var_dump(IntlChar::getFC_NFKC_Closure("\u{2121}"));
var_dump(IntlChar::getFC_NFKC_Closure("\u{1D2D}"));
?>
The above example will output:
string(3) "tel" string(2) "æ"
(PHP 7)
IntlChar::getIntPropertyMaxValue — Get the max value for a Unicode property
$property
) : intGets the maximum value for an enumerated/integer/binary Unicode property.
propertyThe Unicode property to lookup (see the IntlChar::PROPERTY_* constants).
The maximum value returned by IntlChar::getIntPropertyValue() for a Unicode property.
<=0 if the property selector is out of range.
Example #1 Testing different properties
<?php
var_dump(IntlChar::getIntPropertyMaxValue(IntlChar::PROPERTY_BIDI_CLASS));
var_dump(IntlChar::getIntPropertyMaxValue(IntlChar::PROPERTY_SCRIPT));
var_dump(IntlChar::getIntPropertyMaxValue(IntlChar::PROPERTY_IDEOGRAPHIC));
var_dump(IntlChar::getIntPropertyMaxValue(999999999)); // Some made-up value
?>
The above example will output:
int(22) int(166) int(1) int(-1)
(PHP 7)
IntlChar::getIntPropertyMinValue — Get the min value for a Unicode property
$property
) : intGets the minimum value for an enumerated/integer/binary Unicode property.
propertyThe Unicode property to lookup (see the IntlChar::PROPERTY_* constants).
The minimum value returned by IntlChar::getIntPropertyValue() for a Unicode property.
0 if the property selector is out of range.
Example #1 Testing different properties
<?php
var_dump(IntlChar::getIntPropertyMinValue(IntlChar::PROPERTY_BIDI_CLASS));
var_dump(IntlChar::getIntPropertyMinValue(IntlChar::PROPERTY_SCRIPT));
var_dump(IntlChar::getIntPropertyMinValue(IntlChar::PROPERTY_IDEOGRAPHIC));
var_dump(IntlChar::getIntPropertyMinValue(999999999)); // Some made-up value
?>
The above example will output:
int(0) int(0) int(0) int(0)
(PHP 7)
IntlChar::getIntPropertyValue — Get the value for a Unicode property for a code point
Gets the property value for an enumerated or integer Unicode property for a code point. Also returns binary and mask property values.
Returns the numeric value that is directly the property value or, for enumerated properties, corresponds to the numeric value of the enumerated constant of the respective property value enumeration type.
Returns 0 or 1 (for FALSE/TRUE) for binary Unicode properties.
Returns a bit-mask for mask properties.
Returns 0 if property is out of bounds or if the Unicode version does not
have data for the property at all, or not for this code point.
Example #1 Testing different properties
<?php
var_dump(IntlChar::getIntPropertyValue("A", IntlChar::PROPERTY_ALPHABETIC) === 1);
var_dump(IntlChar::getIntPropertyValue("[", IntlChar::PROPERTY_BIDI_MIRRORED) === 1);
var_dump(IntlChar::getIntPropertyValue("Φ", IntlChar::PROPERTY_BLOCK) === IntlChar::BLOCK_CODE_GREEK);
?>
The above example will output:
bool(true) bool(true) bool(true)
(PHP 7)
IntlChar::getNumericValue — Get the numeric value for a Unicode code point
Gets the numeric value for a Unicode code point as defined in the Unicode Character Database.
For characters without any numeric values in the Unicode Character Database, this function will return
IntlChar::NO_NUMERIC_VALUE.
Numeric value of codepoint,
or IntlChar::NO_NUMERIC_VALUE if none is defined. This
constant was added in PHP 7.0.6, prior to this version the literal value
(float)-123456789 may be used instead.
Example #1 Testing different code points
<?php
var_dump(IntlChar::getNumericValue("4"));
var_dump(IntlChar::getNumericValue("x"));
var_dump(IntlChar::getNumericValue("\u{216C}"));
?>
The above example will output:
float(4) float(-123456789) float(50)
(PHP 7)
IntlChar::getPropertyEnum — Get the property constant value for a given property name
$alias
) : intReturns the property constant value for a given property name, as specified in the Unicode database file PropertyAliases.txt. Short, long, and any other variants are recognized.
In addition, this function maps the synthetic names "gcm" / "General_Category_Mask" to the property
IntlChar::PROPERTY_GENERAL_CATEGORY_MASK. These names are not in PropertyAliases.txt.
This function compliments IntlChar::getPropertyName().
aliasThe property name to be matched. The name is compared using "loose matching" as described in PropertyAliases.txt.
Returns an IntlChar::PROPERTY_ constant value,
or IntlChar::PROPERTY_INVALID_CODE if the given name does not match any property.
Example #1 Testing different properties
<?php
var_dump(IntlChar::getPropertyEnum('Bidi_Class') === IntlChar::PROPERTY_BIDI_CLASS);
var_dump(IntlChar::getPropertyEnum('script') === IntlChar::PROPERTY_SCRIPT);
var_dump(IntlChar::getPropertyEnum('IDEOGRAPHIC') === IntlChar::PROPERTY_IDEOGRAPHIC);
var_dump(IntlChar::getPropertyEnum('Some made-up string') === IntlChar::PROPERTY_INVALID_CODE);
?>
The above example will output:
bool(true) bool(true) bool(true) bool(true)
(PHP 7)
IntlChar::getPropertyName — Get the Unicode name for a property
$property
[, int $nameChoice = IntlChar::LONG_PROPERTY_NAME
] ) : stringReturns the Unicode name for a given property, as given in the Unicode database file PropertyAliases.txt.
In addition, this function maps the property IntlChar::PROPERTY_GENERAL_CATEGORY_MASK to the
synthetic names "gcm" / "General_Category_Mask". These names are not in PropertyAliases.txt.
This function compliments IntlChar::getPropertyEnum().
propertyThe Unicode property to lookup (see the IntlChar::PROPERTY_* constants).
IntlChar::PROPERTY_INVALID_CODE should not be used.
Also, if property is out of range, FALSE is returned.
nameChoice
Selector for which name to get. If out of range, FALSE is returned.
All properties have a long name. Most have a short name, but some do not. Unicode allows for additional names;
if present these will be returned by adding 1, 2, etc. to IntlChar::LONG_PROPERTY_NAME.
Returns the name, or FALSE if either the property or the nameChoice
is out of range.
If a given nameChoice returns FALSE, then all larger values of
nameChoice will return FALSE, with one exception: if FALSE is returned for
IntlChar::SHORT_PROPERTY_NAME, then IntlChar::LONG_PROPERTY_NAME
(and higher) may still return a non-FALSE value.
Example #1 Testing different properties
<?php
var_dump(IntlChar::getPropertyName(IntlChar::PROPERTY_BIDI_CLASS));
var_dump(IntlChar::getPropertyName(IntlChar::PROPERTY_BIDI_CLASS, IntlChar::SHORT_PROPERTY_NAME));
var_dump(IntlChar::getPropertyName(IntlChar::PROPERTY_BIDI_CLASS, IntlChar::LONG_PROPERTY_NAME));
var_dump(IntlChar::getPropertyName(IntlChar::PROPERTY_BIDI_CLASS, IntlChar::LONG_PROPERTY_NAME + 1));
?>
The above example will output:
string(10) "Bidi_Class" string(2) "bc" string(10) "Bidi_Class" bool(false)
(PHP 7)
IntlChar::getPropertyValueEnum — Get the property value for a given value name
$property
, string $name
) : intReturns the property value integer for a given value name, as specified in the Unicode database file PropertyValueAliases.txt. Short, long, and any other variants are recognized.
Note:
Some of the names in PropertyValueAliases.txt will only be recognized with
IntlChar::PROPERTY_GENERAL_CATEGORY_MASK, notIntlChar::PROPERTY_GENERAL_CATEGORY. These include:
- "C" / "Other"
- "L" / "Letter"
- "LC" / "Cased_Letter"
- "M" / "Mark"
- "N" / "Number"
- "P" / "Punctuation"
- "S" / "Symbol"
- "Z" / "Separator"
propertyThe Unicode property to lookup (see the IntlChar::PROPERTY_* constants).
If out of range, or this method doesn't work with the given value,
IntlChar::PROPERTY_INVALID_CODE is returned.
nameThe value name to be matched. The name is compared using "loose matching" as described in PropertyValueAliases.txt.
Returns the corresponding value integer, or IntlChar::PROPERTY_INVALID_CODE if the given name
does not match any value of the given property, or if the property is invalid.
Example #1 Testing different properties
<?php
var_dump(IntlChar::getPropertyValueEnum(IntlChar::PROPERTY_BLOCK, 'greek') === IntlChar::BLOCK_CODE_GREEK);
var_dump(IntlChar::getPropertyValueEnum(IntlChar::PROPERTY_BIDI_CLASS, 'RIGHT_TO_LEFT') === IntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT);
var_dump(IntlChar::getPropertyValueEnum(IntlChar::PROPERTY_BIDI_CLASS, 'some made-up string') === IntlChar::PROPERTY_INVALID_CODE);
var_dump(IntlChar::getPropertyValueEnum(123456789, 'RIGHT_TO_LEFT') === IntlChar::PROPERTY_INVALID_CODE);
?>
The above example will output:
bool(true) bool(true) bool(true) bool(true)
(PHP 7)
IntlChar::getPropertyValueName — Get the Unicode name for a property value
$property
, int $value
[, int $nameChoice = IntlChar::LONG_PROPERTY_NAME
] ) : stringReturns the Unicode name for a given property value, as given in the Unicode database file PropertyValueAliases.txt.
Note:
Some of the names in PropertyValueAliases.txt can only be retrieved using
IntlChar::PROPERTY_GENERAL_CATEGORY_MASK, notIntlChar::PROPERTY_GENERAL_CATEGORY. These include:
- "C" / "Other"
- "L" / "Letter"
- "LC" / "Cased_Letter"
- "M" / "Mark"
- "N" / "Number"
- "P" / "Punctuation"
- "S" / "Symbol"
- "Z" / "Separator"
propertyThe Unicode property to lookup (see the IntlChar::PROPERTY_* constants).
If out of range, or this method doesn't work with the given value, FALSE is returned.
value
Selector for a value for the given property. If out of range, FALSE is returned.
In general, valid values range from 0 up to some maximum. There are a couple exceptions:
IntlChar::PROPERTY_BLOCK values begin at the non-zero value IntlChar::BLOCK_CODE_BASIC_LATIN
IntlChar::PROPERTY_CANONICAL_COMBINING_CLASS values are not contiguous and range from 0..240.
nameChoice
Selector for which name to get. If out of range, FALSE is returned.
All values have a long name. Most have a short name, but some do not. Unicode allows for additional names;
if present these will be returned by adding 1, 2, etc. to IntlChar::LONG_PROPERTY_NAME.
Returns the name, or FALSE if either the property or the nameChoice
is out of range.
If a given nameChoice returns FALSE, then all larger values of nameChoice
will return FALSE, with one exception: if FALSE is returned for IntlChar::SHORT_PROPERTY_NAME,
then IntlChar::LONG_PROPERTY_NAME (and higher) may still return a non-FALSE value.
Example #1 Testing different properties
<?php
var_dump(IntlChar::getPropertyValueName(IntlChar::PROPERTY_BLOCK, IntlChar::BLOCK_CODE_GREEK));
var_dump(IntlChar::getPropertyValueName(IntlChar::PROPERTY_BLOCK, IntlChar::BLOCK_CODE_GREEK, IntlChar::SHORT_PROPERTY_NAME));
var_dump(IntlChar::getPropertyValueName(IntlChar::PROPERTY_BLOCK, IntlChar::BLOCK_CODE_GREEK, IntlChar::LONG_PROPERTY_NAME));
var_dump(IntlChar::getPropertyValueName(IntlChar::PROPERTY_BLOCK, IntlChar::BLOCK_CODE_GREEK, IntlChar::LONG_PROPERTY_NAME + 1));
?>
The above example will output:
string(16) "Greek_And_Coptic" string(5) "Greek" string(16) "Greek_And_Coptic" bool(false)
(PHP 7)
IntlChar::getUnicodeVersion — Get the Unicode version
Gets the Unicode version information.
The version array is filled in with the version information for the Unicode standard that is currently used by ICU.
For example, Unicode version 3.1.1 is represented as an array with the values [3, 1, 1, 0].
This function has no parameters.
An array containing the Unicode version number.
Example #1 Testing different properties
<?php
var_dump(IntlChar::getUnicodeVersion());
?>
The above example will output:
array(4) {
[0]=>
int(7)
[1]=>
int(0)
[2]=>
int(0)
[3]=>
int(0)
}
(PHP 7)
IntlChar::hasBinaryProperty — Check a binary Unicode property for a code point
Checks a binary Unicode property for a code point.
Unicode, especially in version 3.2, defines many more properties than the original set in UnicodeData.txt.
The properties APIs are intended to reflect Unicode properties as defined in the Unicode Character Database (UCD) and Unicode Technical Reports (UTR). For details about the properties see » http://www.unicode.org/ucd/. For names of Unicode properties see the UCD file PropertyAliases.txt.
Returns TRUE or FALSE according to the binary Unicode property value for codepoint.
Also FALSE if property is out of bounds or if the Unicode version does not have data for
the property at all, or not for this code point.
Example #1 Testing different properties
<?php
var_dump(IntlChar::hasBinaryProperty("A", IntlChar::PROPERTY_ALPHABETIC));
var_dump(IntlChar::hasBinaryProperty("A", IntlChar::PROPERTY_CASE_SENSITIVE));
var_dump(IntlChar::hasBinaryProperty("A", IntlChar::PROPERTY_BIDI_MIRRORED));
var_dump(IntlChar::hasBinaryProperty("[", IntlChar::PROPERTY_ALPHABETIC));
var_dump(IntlChar::hasBinaryProperty("[", IntlChar::PROPERTY_CASE_SENSITIVE));
var_dump(IntlChar::hasBinaryProperty("[", IntlChar::PROPERTY_BIDI_MIRRORED));
?>
The above example will output:
bool(true) bool(true) bool(false) bool(false) bool(false) bool(true)
(PHP 7)
IntlChar::isalnum — Check if code point is an alphanumeric character
Determines whether the specified code point is an alphanumeric character (letter or digit). TRUE for characters with general categories "L" (letters) and "Nd" (decimal digit numbers).
Returns TRUE if
codepoint is an alphanumeric character, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::isalnum("A"));
var_dump(IntlChar::isalnum("1"));
var_dump(IntlChar::isalnum("\u{2603}"));
?>
The above example will output:
bool(true) bool(true) bool(false)
(PHP 7)
IntlChar::isalpha — Check if code point is a letter character
Determines whether the specified code point is a letter character. TRUE for general categories "L" (letters).
Returns TRUE if
codepoint is a letter character, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::isalpha("A"));
var_dump(IntlChar::isalpha("1"));
var_dump(IntlChar::isalpha("\u{2603}"));
?>
The above example will output:
bool(true) bool(false) bool(false)
(PHP 7)
IntlChar::isbase — Check if code point is a base character
Determines whether the specified code point is a base character. TRUE for general categories "L" (letters),
"N" (numbers), "Mc" (spacing combining marks), and "Me" (enclosing marks).
Note:
This is different from the Unicode definition in chapter 3.5, conformance clause D13, which defines base characters to be all characters (not Cn) that do not graphically combine with preceding characters (M) and that are neither control (Cc) or format (Cf) characters.
Returns TRUE if
codepoint is a base character, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::isbase("A"));
var_dump(IntlChar::isbase("1"));
var_dump(IntlChar::isbase("\u{2603}"));
?>
The above example will output:
bool(true) bool(true) bool(false)
(PHP 7)
IntlChar::isblank — Check if code point is a "blank" or "horizontal space" character
Determines whether the specified code point is a "blank" or "horizontal space", a character that visibly separates words on a line.
The following are equivalent definitions:
TRUE for Unicode White_Space characters except for "vertical space controls" where "vertical space controls" are
the following characters: U+000A (LF) U+000B (VT) U+000C (FF) U+000D (CR) U+0085 (NEL) U+2028 (LS) U+2029 (PS)
TRUE for U+0009 (TAB) and characters with general category "Zs" (space separators) except Zero Width Space (ZWSP, U+200B).
Returns TRUE if
codepoint is either a "blank" or "horizontal space" character, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::isblank("A"));
var_dump(IntlChar::isblank(" "));
var_dump(IntlChar::isblank("\t"));
?>
The above example will output:
bool(false) bool(true) bool(true)
(PHP 7)
IntlChar::iscntrl — Check if code point is a control character
Determines whether the specified code point is a control character.
A control character is one of the following:
IntlChar::CHAR_CATEGORY_CONTROL_CHAR (Cc)IntlChar::CHAR_CATEGORY_FORMAT_CHAR (Cf)IntlChar::CHAR_CATEGORY_LINE_SEPARATOR (Zl)IntlChar::CHAR_CATEGORY_PARAGRAPH_SEPARATOR (Zp)
Returns TRUE if
codepoint is a control character, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::iscntrl("A"));
var_dump(IntlChar::iscntrl(" "));
var_dump(IntlChar::iscntrl("\n"));
var_dump(IntlChar::iscntrl("\u{200e}"));
?>
The above example will output:
bool(false) bool(false) bool(true) bool(true)
IntlChar::PROPERTY_DEFAULT_IGNORABLE_CODE_POINT(PHP 7)
IntlChar::isdefined — Check whether the code point is defined
Determines whether the specified code point is "defined", which usually means that it is assigned a character.
TRUE for general categories other than "Cn" (other, not assigned).
Note:
Note that non-character code points (e.g., U+FDD0) are not "defined" (they are Cn), but surrogate code points are "defined" (Cs).
Returns TRUE if
codepoint is a defined character, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::isdefined("A"));
var_dump(IntlChar::isdefined(" "));
var_dump(IntlChar::isdefined("\u{FDD0}"));
?>
The above example will output:
bool(true) bool(true) bool(false)
(PHP 7)
IntlChar::isdigit — Check if code point is a digit character
Determines whether the specified code point is a digit character.
TRUE for characters with general category "Nd" (decimal digit numbers). Beginning with Unicode 4, this is the same as testing for the Numeric_Type of Decimal.
Returns TRUE if
codepoint is a digit character, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::isdigit("A"));
var_dump(IntlChar::isdigit("1"));
var_dump(IntlChar::isdigit("\t"));
?>
The above example will output:
bool(false) bool(true) bool(false)
(PHP 7)
IntlChar::isgraph — Check if code point is a graphic character
Determines whether the specified code point is a "graphic" character (printable, excluding spaces).
TRUE for all characters except those with general categories "Cc" (control codes), "Cf" (format controls), "Cs" (surrogates), "Cn" (unassigned), and "Z" (separators).
Returns TRUE if
codepoint is a "graphic" character, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::isgraph("A"));
var_dump(IntlChar::isgraph("1"));
var_dump(IntlChar::isgraph("\u{2603}"));
var_dump(IntlChar::isgraph("\n"));
?>
The above example will output:
bool(true) bool(true) bool(true) bool(false)
(PHP 7)
IntlChar::isIDIgnorable — Check if code point is an ignorable character
Determines if the specified character should be regarded as an ignorable character in an identifier.
TRUE for characters with general category "Cf" (format controls) as well as non-whitespace ISO controls (U+0000..U+0008, U+000E..U+001B, U+007F..U+009F).
Note:
Note that Unicode just recommends to ignore Cf (format controls).
Returns TRUE if
codepoint is ignorable in identifiers, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::isIDIgnorable("A"));
var_dump(IntlChar::isIDIgnorable(" "));
var_dump(IntlChar::isIDIgnorable("\u{007F}"));
?>
The above example will output:
bool(false) bool(false) bool(true)
IntlChar::PROPERTY_DEFAULT_IGNORABLE_CODE_POINT(PHP 7)
IntlChar::isIDPart — Check if code point is permissible in an identifier
Determines if the specified character is permissible in an identifier.
TRUE for characters with general categories "L" (letters), "Nl" (letter numbers), "Nd" (decimal digits),
"Mc" and "Mn" (combining marks), "Pc" (connecting punctuation), and u_isIDIgnorable(c).
Note:
This is almost the same as Unicode's ID_Continue (
IntlChar::PROPERTY_ID_CONTINUE) except that Unicode recommends to ignore Cf which is less than IntlChar::isIDIgnorable().
Returns TRUE if
codepoint is the code point may occur in an identifier, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::isIDPart("A"));
var_dump(IntlChar::isIDPart("$"));
var_dump(IntlChar::isIDPart("\n"));
var_dump(IntlChar::isIDPart("\u{2603}"));
?>
The above example will output:
bool(true) bool(false) bool(false) bool(false)
IntlChar::PROPERTY_ID_CONTINUE(PHP 7)
IntlChar::isIDStart — Check if code point is permissible as the first character in an identifier
Determines if the specified character is permissible as the first character in an identifier according to Unicode (The Unicode Standard, Version 3.0, chapter 5.16 Identifiers).
TRUE for characters with general categories "L" (letters) and "Nl" (letter numbers).
Returns TRUE if
codepoint may start an identifier, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::isIDStart("A"));
var_dump(IntlChar::isIDStart("$"));
var_dump(IntlChar::isIDStart("\n"));
var_dump(IntlChar::isIDStart("\u{2603}"));
?>
The above example will output:
bool(true) bool(false) bool(false) bool(false)
IntlChar::PROPERTY_ID_START(PHP 7)
IntlChar::isISOControl — Check if code point is an ISO control code
Determines whether the specified code point is an ISO control code.
TRUE for U+0000..U+001f and U+007f..U+009f (general category "Cc").
Returns TRUE if
codepoint is an ISO control code, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::isISOControl(" "));
var_dump(IntlChar::isISOControl("\n"));
var_dump(IntlChar::isISOControl("\u{200e}"));
?>
The above example will output:
bool(false) bool(true) bool(false)
(PHP 7)
IntlChar::isJavaIDPart — Check if code point is permissible in a Java identifier
Determines if the specified character is permissible in a Java identifier.
In addition to IntlChar::isIDPart(), TRUE for characters with general category "Sc" (currency symbols).
Returns TRUE if
codepoint may occur in a Java identifier, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::isJavaIDPart("A"));
var_dump(IntlChar::isJavaIDPart("$"));
var_dump(IntlChar::isJavaIDPart("\n"));
var_dump(IntlChar::isJavaIDPart("\u{2603}"));
?>
The above example will output:
bool(true) bool(true) bool(false) bool(false)
(PHP 7)
IntlChar::isJavaIDStart — Check if code point is permissible as the first character in a Java identifier
Determines if the specified character is permissible as the start of a Java identifier.
In addition to IntlChar::isIDStart(), TRUE for characters with general categories "Sc" (currency symbols) and "Pc" (connecting punctuation).
Returns TRUE if
codepoint may start a Java identifier, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::isJavaIDStart("A"));
var_dump(IntlChar::isJavaIDStart("$"));
var_dump(IntlChar::isJavaIDStart("\n"));
var_dump(IntlChar::isJavaIDStart("\u{2603}"));
?>
The above example will output:
bool(true) bool(true) bool(false) bool(false)
(PHP 7)
IntlChar::isJavaSpaceChar — Check if code point is a space character according to Java
Determine if the specified code point is a space character according to Java.
TRUE for characters with general categories "Z" (separators), which does not include control codes (e.g., TAB or Line Feed).
Returns TRUE if
codepoint is a space character according to Java, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::isJavaSpaceChar("A"));
var_dump(IntlChar::isJavaSpaceChar(" "));
var_dump(IntlChar::isJavaSpaceChar("\n"));
var_dump(IntlChar::isJavaSpaceChar("\t"));
var_dump(IntlChar::isJavaSpaceChar("\u{00A0}"));
?>
The above example will output:
bool(false) bool(true) bool(false) bool(false) bool(true)
(PHP 7)
IntlChar::islower — Check if code point is a lowercase letter
Determines whether the specified code point has the general category "Ll" (lowercase letter).
Note:
This misses some characters that are also lowercase but have a different general category value. In order to include those, use IntlChar::isULowercase().
Returns TRUE if
codepoint is an Ll lowercase letter, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::islower("A"));
var_dump(IntlChar::islower("a"));
var_dump(IntlChar::islower("Φ"));
var_dump(IntlChar::islower("φ"));
var_dump(IntlChar::islower("1"));
?>
The above example will output:
bool(false) bool(true) bool(false) bool(true) bool(false)
IntlChar::PROPERTY_LOWERCASE(PHP 7)
IntlChar::isMirrored — Check if code point has the Bidi_Mirrored property
Determines whether the code point has the Bidi_Mirrored property.
This property is set for characters that are commonly used in Right-To-Left contexts and need to be displayed with a "mirrored" glyph.
Returns TRUE if
codepoint has the Bidi_Mirrored property, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::isMirrored("A"));
var_dump(IntlChar::isMirrored("<"));
var_dump(IntlChar::isMirrored("("));
?>
The above example will output:
bool(false) bool(true) bool(true)
IntlChar::PROPERTY_BIDI_MIRRORED(PHP 7)
IntlChar::isprint — Check if code point is a printable character
Determines whether the specified code point is a printable character.
TRUE for general categories other than "C" (controls).
Returns TRUE if
codepoint is a printable character, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::isprint("A"));
var_dump(IntlChar::isprint(" "));
var_dump(IntlChar::isprint("\n"));
var_dump(IntlChar::isprint("\u{200e}"));
?>
The above example will output:
bool(true) bool(true) bool(false) bool(false)
IntlChar::PROPERTY_DEFAULT_IGNORABLE_CODE_POINT(PHP 7)
IntlChar::ispunct — Check if code point is punctuation character
Determines whether the specified code point is a punctuation character.
TRUE for characters with general categories "P" (punctuation).
Returns TRUE if
codepoint is a punctuation character, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::ispunct("."));
var_dump(IntlChar::ispunct(","));
var_dump(IntlChar::ispunct("\n"));
var_dump(IntlChar::ispunct("$"));
The above example will output:
bool(true) bool(true) bool(false) bool(false)
(PHP 7)
IntlChar::isspace — Check if code point is a space character
Determines if the specified character is a space character or not.
Returns TRUE if
codepoint is a space character, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::isspace("A"));
var_dump(IntlChar::isspace(" "));
var_dump(IntlChar::isspace("\n"));
var_dump(IntlChar::isspace("\t"));
var_dump(IntlChar::isspace("\u{00A0}"));
?>
The above example will output:
bool(false) bool(true) bool(true) bool(true) bool(true)
(PHP 7)
IntlChar::istitle — Check if code point is a titlecase letter
Determines whether the specified code point is a titlecase letter.
TRUE for general category "Lt" (titlecase letter).
Returns TRUE if
codepoint is a titlecase letter, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::istitle("A"));
var_dump(IntlChar::istitle("a"));
var_dump(IntlChar::istitle("Φ"));
var_dump(IntlChar::istitle("φ"));
var_dump(IntlChar::istitle("1"));
?>
The above example will output:
bool(false) bool(true) bool(false) bool(true) bool(false)
(PHP 7)
IntlChar::isUAlphabetic — Check if code point has the Alphabetic Unicode property
Check if a code point has the Alphabetic Unicode property.
This is the same as IntlChar::hasBinaryProperty($codepoint, IntlChar::PROPERTY_ALPHABETIC)
Returns TRUE if
codepoint has the Alphabetic Unicode property, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::isUAlphabetic("A"));
var_dump(IntlChar::isUAlphabetic("1"));
var_dump(IntlChar::isUAlphabetic("\u{2603}"));
?>
The above example will output:
bool(true) bool(false) bool(false)
IntlChar::PROPERTY_ALPHABETIC(PHP 7)
IntlChar::isULowercase — Check if code point has the Lowercase Unicode property
Check if a code point has the Lowercase Unicode property.
This is the same as IntlChar::hasBinaryProperty($codepoint, IntlChar::PROPERTY_LOWERCASE)
Note:
This is different than IntlChar::islower() and will return
TRUEfor more characters.
Returns TRUE if
codepoint has the Lowercase Unicode property, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::isULowercase("A"));
var_dump(IntlChar::isULowercase("a"));
var_dump(IntlChar::isULowercase("Φ"));
var_dump(IntlChar::isULowercase("φ"));
var_dump(IntlChar::isULowercase("1"));
?>
The above example will output:
bool(false) bool(true) bool(false) bool(true) bool(false)
IntlChar::PROPERTY_LOWERCASE(PHP 7)
IntlChar::isupper — Check if code point has the general category "Lu" (uppercase letter)
Determines whether the specified code point has the general category "Lu" (uppercase letter).
Note:
This misses some characters that are also uppercase but have a different general category value. In order to include those, use IntlChar::isUUppercase().
Returns TRUE if
codepoint is an Lu uppercase letter, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::isupper("A"));
var_dump(IntlChar::isupper("a"));
var_dump(IntlChar::isupper("Φ"));
var_dump(IntlChar::isupper("φ"));
var_dump(IntlChar::isupper("1"));
?>
The above example will output:
bool(true) bool(false) bool(true) bool(false) bool(false)
IntlChar::PROPERTY_UPPERCASE(PHP 7)
IntlChar::isUUppercase — Check if code point has the Uppercase Unicode property
Check if a code point has the Uppercase Unicode property.
This is the same as IntlChar::hasBinaryProperty($codepoint, IntlChar::PROPERTY_UPPERCASE)
Note:
This is different than IntlChar::isupper() and will return
TRUEfor more characters.
Returns TRUE if
codepoint has the Uppercase Unicode property, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::isUUppercase("A"));
var_dump(IntlChar::isUUppercase("a"));
var_dump(IntlChar::isUUppercase("Φ"));
var_dump(IntlChar::isUUppercase("φ"));
var_dump(IntlChar::isUUppercase("1"));
?>
The above example will output:
bool(true) bool(false) bool(true) bool(false) bool(false)
IntlChar::PROPERTY_UPPERCASE(PHP 7)
IntlChar::isUWhiteSpace — Check if code point has the White_Space Unicode property
Check if a code point has the White_Space Unicode property.
This is the same as IntlChar::hasBinaryProperty($codepoint, IntlChar::PROPERTY_WHITE_SPACE)
Note:
This is different from both IntlChar::isspace() and IntlChar::isWhitespace().
Returns TRUE if
codepoint has the White_Space Unicode property, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::isUWhiteSpace("A"));
var_dump(IntlChar::isUWhiteSpace(" "));
var_dump(IntlChar::isUWhiteSpace("\n"));
var_dump(IntlChar::isUWhiteSpace("\t"));
var_dump(IntlChar::isUWhiteSpace("\u{00A0}"));
?>
The above example will output:
bool(false) bool(true) bool(true) bool(true) bool(true)
IntlChar::PROPERTY_WHITE_SPACE(PHP 7)
IntlChar::isWhitespace — Check if code point is a whitespace character according to ICU
Determines if the specified code point is a whitespace character according to ICU.
A character is considered to be a ICU whitespace character if and only if it satisfies one of the following criteria:
Returns TRUE if
codepoint is a whitespace character according to ICU, FALSE if not.
Example #1 Testing different code points
<?php
var_dump(IntlChar::iswhitespace("A"));
var_dump(IntlChar::iswhitespace(" "));
var_dump(IntlChar::iswhitespace("\n"));
var_dump(IntlChar::iswhitespace("\t"));
var_dump(IntlChar::iswhitespace("\u{00A0}"));
?>
The above example will output:
bool(false) bool(true) bool(true) bool(true) bool(false)
(PHP 7)
IntlChar::isxdigit — Check if code point is a hexadecimal digit
Determines whether the specified code point is a hexadecimal digit.
TRUE for characters with general category "Nd" (decimal digit numbers) as
well as Latin letters a-f and A-F in both ASCII and Fullwidth ASCII.
(That is, for letters with code points 0041..0046, 0061..0066, FF21..FF26, FF41..FF46.)
This is equivalent to IntlChar::digit($codepoint, 16) >= 0.
Returns TRUE if
codepoint is a hexadecimal character, FALSE if not.
Note:
In order to narrow the definition of hexadecimal digits to only ASCII characters use:
<?php
$isASCIIHexadecimal = IntlChar::ord($codepoint) <= 0x7F && IntlChar::isxdigit($codepoint);
?>
Example #1 Testing different code points
<?php
var_dump(IntlChar::isxdigit("A"));
var_dump(IntlChar::isxdigit("1"));
var_dump(IntlChar::isxdigit("\u{2603}"));
?>
The above example will output:
bool(true) bool(true) bool(false)
(PHP 7)
IntlChar::ord — Return Unicode code point value of character
Returns the Unicode code point value of the given character.
This function compliments IntlChar::chr().
characterA Unicode character.
Returns the Unicode code point value as an integer.
Example #1 Testing different code points
<?php
var_dump(IntlChar::ord("A"));
var_dump(IntlChar::ord(" "));
var_dump(IntlChar::ord("\u{2603}"));
?>
The above example will output:
int(65) int(32) int(9731)
(PHP 7)
IntlChar::tolower — Make Unicode character lowercase
The given character is mapped to its lowercase equivalent. If the character has no lowercase equivalent, the original character itself is returned.
Returns the Simple_Lowercase_Mapping of the code point, if any; otherwise the code point itself.
The return type will be integer unless the code point was passed as a UTF-8 string, in which case a string will be returned.
Example #1 Testing different code points
<?php
var_dump(IntlChar::tolower("A"));
var_dump(IntlChar::tolower("a"));
var_dump(IntlChar::tolower("Φ"));
var_dump(IntlChar::tolower("φ"));
var_dump(IntlChar::tolower("1"));
var_dump(IntlChar::tolower(ord("A")));
var_dump(IntlChar::tolower(ord("a")));
?>
The above example will output:
string(1) "a" string(1) "a" string(2) "φ" string(2) "φ" string(1) "1" int(97) int(97)
(PHP 7)
IntlChar::totitle — Make Unicode character titlecase
The given character is mapped to its titlecase equivalent. If the character has no titlecase equivalent, the original character itself is returned.
Returns the Simple_Titlecase_Mapping of the code point, if any; otherwise the code point itself.
The return type will be integer unless the code point was passed as a UTF-8 string, in which case a string will be returned.
Example #1 Testing different code points
<?php
var_dump(IntlChar::totitle("A"));
var_dump(IntlChar::totitle("a"));
var_dump(IntlChar::totitle("Φ"));
var_dump(IntlChar::totitle("φ"));
var_dump(IntlChar::totitle("1"));
var_dump(IntlChar::totitle(ord("A")));
var_dump(IntlChar::totitle(ord("a")));
?>
The above example will output:
string(1) "A" string(1) "A" string(2) "Φ" string(2) "Φ" string(1) "1" int(65) int(65)
(PHP 7)
IntlChar::toupper — Make Unicode character uppercase
The given character is mapped to its uppercase equivalent. If the character has no uppercase equivalent, the character itself is returned.
Returns the Simple_Uppercase_Mapping of the code point, if any; otherwise the code point itself.
The return type will be integer unless the code point was passed as a UTF-8 string, in which case a string will be returned.
Example #1 Testing different code points
<?php
var_dump(IntlChar::toupper("A"));
var_dump(IntlChar::toupper("a"));
var_dump(IntlChar::toupper("Φ"));
var_dump(IntlChar::toupper("φ"));
var_dump(IntlChar::toupper("1"));
var_dump(IntlChar::toupper(ord("A")));
var_dump(IntlChar::toupper(ord("a")));
?>
The above example will output:
string(1) "A" string(1) "A" string(2) "Φ" string(2) "Φ" string(1) "1" int(65) int(65)
(PHP 5 > 5.5.0, PHP 7, PECL intl > 3.0.0a1)
This class is used for generating exceptions when errors occur inside intl functions. Such exceptions are only generated when intl.use_exceptions is enabled.
(PHP 5 >= 5.5.0, PHP 7)
This class represents iterator objects throughout the intl extension
whenever the iterator cannot be identified with any other object provided
by the extension. The distinct iterator object used internally by the
foreach
construct can only be obtained (in the relevant part here) from
objects, so objects of this class serve the purpose of providing the hook
through which this internal object can be obtained. As a convenience, this
class also implements the Iterator interface,
allowing the collection of values to be navigated using the methods
defined in that interface. Both these methods and the internal iterator
objects provided to foreach are backed by the same
state (e.g. the position of the iterator and its current value).
Subclasses may provide richer functionality.
(PHP 5 >= 5.5.0, PHP 7)
IntlIterator::current — Get the current element
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7)
IntlIterator::key — Get the current key
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7)
IntlIterator::next — Move forward to the next element
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7)
IntlIterator::rewind — Rewind the iterator to the first element
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.5.0, PHP 7)
IntlIterator::valid — Check if current position is valid
This function is currently not documented; only its argument list is available.
This function has no parameters.
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
intl_error_name — Get symbolic name for a given error code
$error_code
) : stringReturn ICU error code name.
error_codeICU error code.
The returned string will be the same as the name of the error code constant.
Example #1 intl_error_name() example
<?php
$coll = collator_create( 'en_RU' );
$err_code = collator_get_error_code( $coll );
printf( "Symbolic name for %d is %s\n.", $err_code, intl_error_name( $err_code ) );
?>
The above example will output something similar to:
Symbolic name for -128 is U_USING_FALLBACK_WARNING.
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
intl_get_error_code — Get the last error code
Useful to handle errors occurred in static methods when there's no object to get error code from.
Error code returned by the last API function call.
Example #1 intl_get_error_code() example
<?php
$coll = collator_create( '<bad_param>' );
if( !$coll ) {
handle_error( intl_get_error_code() );
}
?>
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
intl_get_error_message — Get description of the last error
Get error message from last internationalization function called.
Description of an error occurred in the last API function call.
Example #1 intl_get_error_message() example
<?php
if( Collator::getAvailableLocales() === false ) {
show_error( intl_get_error_message() );
}
?>
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
intl_is_failure — Check whether the given error code indicates failure
$error_code
) : bool
error_codeis a value that returned by functions: intl_get_error_code(), collator_get_error_code() .
TRUE if it the code indicates some failure, and FALSE
in case of success or a warning.
Example #1 intl_is_failure() example
<?php
function check( $err_code )
{
var_export( intl_is_failure( $err_code ) );
echo "\n";
}
check( U_ZERO_ERROR );
check( U_USING_FALLBACK_WARNING );
check( U_ILLEGAL_ARGUMENT_ERROR );
?>
The above example will output something similar to:
false false true
While there are many languages in which every necessary character can be represented by a one-to-one mapping to an 8-bit value, there are also several languages which require so many characters for written communication that they cannot be contained within the range a mere byte can code (A byte is made up of eight bits. Each bit can contain only two distinct values, one or zero. Because of this, a byte can only represent 256 unique values (two to the power of eight)). Multibyte character encoding schemes were developed to express more than 256 characters in the regular bytewise coding system.
When you manipulate (trim, split, splice, etc.) strings encoded in a multibyte encoding, you need to use special functions since two or more consecutive bytes may represent a single character in such encoding schemes. Otherwise, if you apply a non-multibyte-aware string function to the string, it probably fails to detect the beginning or ending of the multibyte character and ends up with a corrupted garbage string that most likely loses its original meaning.
mbstring provides multibyte specific string functions
that help you deal with multibyte encodings in PHP. In addition to that,
mbstring handles character encoding conversion between
the possible encoding pairs. mbstring is designed to
handle Unicode-based encodings such as UTF-8 and UCS-2 and many
single-byte encodings for convenience (listed below).
No external libraries are needed to build this extension.
mbstring is a non-default extension. This means it
is not enabled by default. You must explicitly enable the module with
the configure option. See the
Install section for details.
The following configure options are related to the
mbstring module.
--enable-mbstring: Enable
mbstring functions. This option is
required to use mbstring functions.
libmbfl is necessary for mbstring.
libmbfl is bundled with mbstring.
Before PHP 7.3.0, if libmbfl is already installed on the system,
--with-libmbfl[=DIR] can be specified to use
the installed library.
--disable-mbregex: Disable regular expression functions with multibyte character support.
Oniguruma is necessary for the regular
expression functions with multibyte character support.
Oniguruma is bundled with
mbstring. As of PHP 5.4.0, if
Oniguruma is already installed on the system,
--with-onig[=DIR] can be specified to
use the installed library.
As of PHP 7.4.0 --with-onig has been removed
and pkg-config is now used to detect the libonig library.
As of PHP 5.4.0 it is possible to disable the multibyte regex backtrack check by specifying --disable-mbregex-backtrack.
The behaviour of these functions is affected by settings in php.ini.
| Name | Default | Changeable | Changelog |
|---|---|---|---|
| mbstring.language | "neutral" | PHP_INI_ALL | PHP_INI_PERDIR in PHP <= 5.2.6. |
| mbstring.detect_order | NULL | PHP_INI_ALL | |
| mbstring.http_input | "pass" | PHP_INI_ALL | Deprecated in PHP 5.6.0. |
| mbstring.http_output | "pass" | PHP_INI_ALL | Deprecated in PHP 5.6.0. |
| mbstring.internal_encoding | NULL | PHP_INI_ALL | Deprecated in PHP 5.6.0. |
| mbstring.script_encoding | NULL | PHP_INI_ALL | Removed in PHP 5.4.0. Use zend.script_encoding instead. |
| mbstring.substitute_character | NULL | PHP_INI_ALL | |
| mbstring.func_overload | "0" | PHP_INI_SYSTEM | PHP_INI_PERDIR in PHP <= 5.2.6. Deprecated in PHP 7.2.0. |
| mbstring.encoding_translation | "0" | PHP_INI_PERDIR | |
| mbstring.http_output_conv_mimetypes | "^(text/|application/xhtml\+xml)" | PHP_INI_ALL | Available as of PHP 5.3.0. |
| mbstring.strict_detection | "0" | PHP_INI_ALL | Available as of PHP 5.1.2. |
Here's a short explanation of the configuration directives.
mbstring.language
string
The default national language setting (NLS) used in mbstring. Note that this option
automagically defines mbstring.internal_encoding and
mbstring.internal_encoding should be placed
after mbstring.language in php.ini
mbstring.encoding_translation
boolean
Enables the transparent character encoding filter for the incoming HTTP queries, which performs detection and conversion of the input encoding to the internal character encoding.
mbstring.internal_encoding
string
This feature has been DEPRECATED as of PHP 5.6.0. Relying on this feature is highly discouraged.
Defines the default internal character encoding.
PHP 5.6 and later users should leave this empty and set
default_charset
instead.
mbstring.http_input
string
This feature has been DEPRECATED as of PHP 5.6.0. Relying on this feature is highly discouraged.
Defines the default HTTP input character encoding.
PHP 5.6 and later users should leave this empty and set
default_charset
instead.
mbstring.http_output
string
This feature has been DEPRECATED as of PHP 5.6.0. Relying on this feature is highly discouraged.
Defines the default HTTP output character encoding (output will be converted from the internal encoding to the HTTP output encoding upon output).
PHP 5.6 and later users should leave this empty and set
default_charset
instead.
mbstring.detect_order
string
Defines default character code detection order. See also mb_detect_order().
mbstring.substitute_character
string
Defines character to substitute for invalid character encoding. See mb_substitute_character() for supported values.
mbstring.func_overload
string
This feature has been DEPRECATED as of PHP 7.2.0. Relying on this feature is highly discouraged.
Overloads a set of single byte functions by the mbstring counterparts. See Function overloading for more information.
This setting can only be changed from the php.ini file.
mbstring.http_output_conv_mimetypes
string
mbstring.strict_detection
boolean
Enables the strict encoding detection.
According to the » HTML 4.01 specification, Web browsers are allowed to encode a form being submitted with a character encoding different from the one used for the page. See mb_http_input() to detect character encoding used by browsers.
Although popular browsers are capable of giving a reasonably accurate guess
to the character encoding of a given HTML document, it would be better to
set the charset parameter in the
Content-Type HTTP header to the appropriate value by
header() or
default_charset ini setting.
Example #1 php.ini setting examples
; Set default language
mbstring.language = Neutral; Set default language to Neutral(UTF-8) (default)
mbstring.language = English; Set default language to English
mbstring.language = Japanese; Set default language to Japanese
;; Set default internal encoding
;; Note: Make sure to use character encoding works with PHP
mbstring.internal_encoding = UTF-8 ; Set internal encoding to UTF-8
;; HTTP input encoding translation is enabled.
mbstring.encoding_translation = On
;; Set default HTTP input character encoding
;; Note: Script cannot change http_input setting.
mbstring.http_input = pass ; No conversion.
mbstring.http_input = auto ; Set HTTP input to auto
; "auto" is expanded according to mbstring.language
mbstring.http_input = SJIS ; Set HTTP input to SJIS
mbstring.http_input = UTF-8,SJIS,EUC-JP ; Specify order
;; Set default HTTP output character encoding
mbstring.http_output = pass ; No conversion
mbstring.http_output = UTF-8 ; Set HTTP output encoding to UTF-8
;; Set default character encoding detection order
mbstring.detect_order = auto ; Set detect order to auto
mbstring.detect_order = ASCII,JIS,UTF-8,SJIS,EUC-JP ; Specify order
;; Set default substitute character
mbstring.substitute_character = 12307 ; Specify Unicode value
mbstring.substitute_character = none ; Do not print character
mbstring.substitute_character = long ; Long Example: U+3000,JIS+7E7E
Example #2 php.ini setting for EUC-JP users
;; Disable Output Buffering output_buffering = Off ;; Set HTTP header charset default_charset = EUC-JP ;; Set default language to Japanese mbstring.language = Japanese ;; HTTP input encoding translation is enabled. mbstring.encoding_translation = On ;; Set HTTP input encoding conversion to auto mbstring.http_input = auto ;; Convert HTTP output to EUC-JP mbstring.http_output = EUC-JP ;; Set internal encoding to EUC-JP mbstring.internal_encoding = EUC-JP ;; Do not print invalid characters mbstring.substitute_character = none
Example #3 php.ini setting for SJIS users
;; Enable Output Buffering output_buffering = On ;; Set mb_output_handler to enable output conversion output_handler = mb_output_handler ;; Set HTTP header charset default_charset = Shift_JIS ;; Set default language to Japanese mbstring.language = Japanese ;; Set http input encoding conversion to auto mbstring.http_input = auto ;; Convert to SJIS mbstring.http_output = SJIS ;; Set internal encoding to EUC-JP mbstring.internal_encoding = EUC-JP ;; Do not print invalid characters mbstring.substitute_character = none
This extension has no resource types defined.
The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.
MB_OVERLOAD_MAIL
(integer)
MB_OVERLOAD_STRING
(integer)
MB_OVERLOAD_REGEX
(integer)
MB_CASE_UPPER
(integer)
MB_CASE_LOWER
(integer)
MB_CASE_TITLE
(integer)
MB_CASE_FOLD
(integer)
MB_CASE_LOWER_SIMPLE
(integer)
MB_CASE_UPPER_SIMPLE
(integer)
MB_CASE_TITLE_SIMPLE
(integer)
MB_CASE_FOLD_SIMPLE
(integer)
MB_ONIGURUMA_VERSION
(string)
6.9.4.
Available as of PHP 7.4.
| Name in the IANA character set registry | Underlying character set | Description | Additional note |
|---|---|---|---|
| ISO-10646-UCS-4 | ISO 10646 | The Universal Character Set with 31-bit code space, standardized as UCS-4 by ISO/IEC 10646. It is kept synchronized with the latest version of the Unicode code map. | If this name is used in the encoding conversion facility, the converter attempts to identify by the preceding BOM (byte order mark)in which endian the subsequent bytes are represented. |
| ISO-10646-UCS-4 | UCS-4 | See above. |
In contrast to UCS-4, strings are always assumed
to be in big endian form.
|
| ISO-10646-UCS-4 | UCS-4 | See above. |
In contrast to UCS-4, strings are always assumed
to be in little endian form.
|
| ISO-10646-UCS-2 | UCS-2 | The Universal Character Set with 16-bit code space, standardized as UCS-2 by ISO/IEC 10646. It is kept synchronized with the latest version of the unicode code map. | If this name is used in the encoding conversion facility, the converter attempts to identify by the preceding BOM (byte order mark)in which endian the subsequent bytes are represented. |
| ISO-10646-UCS-2 | UCS-2 | See above. |
In contrast to UCS-2, strings are always assumed
to be in big endian form.
|
| ISO-10646-UCS-2 | UCS-2 | See above. |
In contrast to UCS-2, strings are always assumed
to be in little endian form.
|
| UTF-32 | Unicode | Unicode Transformation Format of 32-bit unit width, whose encoding space refers to the Unicode's codeset standard. This encoding scheme wasn't identical to UCS-4 because the code space of Unicode were limited to a 21-bit value. | If this name is used in the encoding conversion facility, the converter attempts to identify by the preceding BOM (byte order mark)in which endian the subsequent bytes are represented. |
| UTF-32BE | Unicode | See above |
In contrast to UTF-32, strings are always assumed
to be in big endian form.
|
| UTF-32LE | Unicode | See above |
In contrast to UTF-32, strings are always assumed
to be in little endian form.
|
| UTF-16 | Unicode | Unicode Transformation Format of 16-bit unit width. It's worth a note that UTF-16 is no longer the same specification as UCS-2 because the surrogate mechanism has been introduced since Unicode 2.0 and UTF-16 now refers to a 21-bit code space. | If this name is used in the encoding conversion facility, the converter attempts to identify by the preceding BOM (byte order mark)in which endian the subsequent bytes are represented. |
| UTF-16BE | Unicode | See above. |
In contrast to UTF-16, strings are always assumed
to be in big endian form.
|
| UTF-16LE | Unicode | See above. |
In contrast to UTF-16, strings are always assumed
to be in little endian form.
|
| UTF-8 | Unicode / UCS | Unicode Transformation Format of 8-bit unit width. | none |
| UTF-7 | Unicode | A mail-safe transformation format of Unicode, specified in » RFC2152. | none |
| (none) | Unicode | A variant of UTF-7 which is specialized for use in the » IMAP protocol. | none |
| US-ASCII (preferred MIME name) / iso-ir-6 / ANSI_X3.4-1986 / ISO_646.irv:1991 / ASCII / ISO646-US / us / IBM367 / CP367 / csASCII | ASCII / ISO 646 | American Standard Code for Information Interchange is a commonly-used 7-bit encoding. Also standardized as an international standard, ISO 646. | (none) |
| EUC-JP (preferred MIME name) / Extended_UNIX_Code_Packed_Format_for_Japanese / csEUCPkdFmtJapanese | Compound of US-ASCII / JIS X0201:1997 (hankaku kana part) / JIS X0208:1990 / JIS X0212:1990 | As you see the name is derived from an abbreviation of Extended UNIX Code Packed Format for Japanese, this encoding is mostly used on UNIX or alike platforms. The original encoding scheme, Extended UNIX Code, is designed on the basis of ISO 2022. | The character set referred to by EUC-JP is different to IBM932 / CP932, which are used by OS/2® and Microsoft® Windows®. For information interchange with those platforms, use EUCJP-WIN instead. |
| Shift_JIS (preferred MIME name) / MS_Kanji / csShift_JIS | Compound of JIS X0201:1997 / JIS X0208:1997 | Shift_JIS was developed in early 80's, at the time personal Japanese word processors were brought into the market, in order to maintain compatibilities with the legacy encoding scheme JIS X 0201:1976. According to the IANA definition the codeset of Shift_JIS is slightly different to IBM932 / CP932. However, the names "SJIS" / "Shift_JIS" are often wrongly used to refer to these codesets. | For the CP932 codemap, use SJIS-WIN instead. |
| (none) | Compound of JIS X0201:1997 / JIS X0208:1997 / IBM extensions / NEC extensions | While this "encoding" uses the same encoding scheme as EUC-JP, the underlying character set is different. That is, some code points map to different characters than EUC-JP. | none |
| Windows-31J / csWindows31J | Compound of JIS X0201:1997 / JIS X0208:1997 / IBM extensions / NEC extensions | While this "encoding" uses the same encoding scheme as Shift_JIS, the underlying character set is different. That means some code points map to different characters than Shift_JIS. | (none) |
| ISO-2022-JP (preferred MIME name) / csISO2022JP | US-ASCII / JIS X0201:1976 / JIS X0208:1978 / JIS X0208:1983 | » RFC1468 | (none) |
| JIS | |||
| ISO-8859-1 | |||
| ISO-8859-2 | |||
| ISO-8859-3 | |||
| ISO-8859-4 | |||
| ISO-8859-5 | |||
| ISO-8859-6 | |||
| ISO-8859-7 | |||
| ISO-8859-8 | |||
| ISO-8859-9 | |||
| ISO-8859-10 | |||
| ISO-8859-13 | |||
| ISO-8859-14 | |||
| ISO-8859-15 | |||
| ISO-8859-16 | |||
| byte2be | |||
| byte2le | |||
| byte4be | |||
| byte4le | |||
| BASE64 | |||
| HTML-ENTITIES | |||
| 7bit | |||
| 8bit | |||
| EUC-CN | |||
| CP936 | |||
| HZ | |||
| EUC-TW | |||
| CP950 | |||
| BIG-5 | |||
| EUC-KR | |||
| UHC (CP949) | |||
| ISO-2022-KR | |||
| Windows-1251 (CP1251) | |||
| Windows-1252 (CP1252) | |||
| CP866 (IBM866) | |||
| KOI8-R | |||
| KOI8-U |
Japanese characters can only be represented by multibyte encodings, and multiple encoding standards are used depending on platform and text purpose. To make matters worse, these encoding standards differ slightly from one another. In order to create a web application which would be usable in a Japanese environment, a developer has to keep these complexities in mind to ensure that the proper character encodings are used.
00h to 7fh).
HTTP input/output character encoding conversion may convert binary data also. Users are supposed to control character encoding conversion if binary data is used for HTTP input/output.
Note:
If
enctypefor HTML form is set tomultipart/form-dataandmbstring.encoding_translationis set to On in php.ini the POST'ed variables and the names of uploaded files will be converted to the internal character encoding as well. However, the conversion isn't applied to the query keys.
There is no way to control HTTP input character conversion from a PHP script. To disable HTTP input character conversion, it has to be done in php.ini.
Example #1 Disable HTTP input conversion in php.ini
;; Disable HTTP Input conversion mbstring.http_input = pass ;; Disable HTTP Input conversion mbstring.encoding_translation = Off
When using PHP as an Apache module, it is possible to override those settings in each Virtual Host directive in httpd.conf or per directory with .htaccess. Refer to the Configuration section and Apache Manual for details.
There are several ways to enable output character encoding
conversion. One is using php.ini, another
is using ob_start() with
mb_output_handler() as the
ob_start callback function.
Example #2 php.ini setting example
;; Enable output character encoding conversion for all PHP pages ;; Enable Output Buffering output_buffering = On ;; Set mb_output_handler to enable output conversion output_handler = mb_output_handler
Example #3 Script example
<?php
// Enable output character encoding conversion only for this page
// Set HTTP output character encoding to SJIS
mb_http_output('SJIS');
// Start buffering and specify "mb_output_handler" as
// callback function
ob_start('mb_output_handler');
?>
Currently the following character encodings are supported by the
mbstring module. Any of those Character encodings
can be specified in the encoding parameter of
mbstring functions.
The following character encodings are supported in this PHP extension:
* denotes encodings usable also in regular expressions.
** denotes encodings available since PHP 5.4.0.
Any php.ini entry which accepts an encoding name
can also use the values "auto" and
"pass".
mbstring functions which accept an encoding
name can also use the value "auto".
If "pass" is set, no character
encoding conversion is performed.
If "auto" is set, it is expanded to
the list of encodings defined per the NLS.
For instance, if the NLS is set to Japanese,
the value is assumed to be
"ASCII,JIS,UTF-8,EUC-JP,SJIS".
See also mb_detect_order()
This feature has been DEPRECATED as of PHP 7.2.0. Relying on this feature is highly discouraged.
You might often find it difficult to get an existing PHP application to work in a given multibyte environment. This happens because most PHP applications out there are written with the standard string functions such as substr(), which are known to not properly handle multibyte-encoded strings.
mbstring supports a 'function overloading' feature which enables you to add multibyte awareness to such an application without code modification by overloading multibyte counterparts on the standard string functions. For example, mb_substr() is called instead of substr() if function overloading is enabled. This feature makes it easy to port applications that only support single-byte encodings to a multibyte environment in many cases.
To use function overloading, set
mbstring.func_overload in php.ini to a
positive value that represents a combination of bitmasks specifying
the categories of functions to be overloaded. It should be set
to 1 to overload the mail() function. 2 for string
functions, 4 for regular expression functions. For example,
if it is set to 7, mail, strings and regular expression functions will
be overloaded. The list of overloaded functions are shown below.
| value of mbstring.func_overload | original function | overloaded function |
|---|---|---|
| 1 | mail() | mb_send_mail() |
| 2 | strlen() | mb_strlen() |
| 2 | strpos() | mb_strpos() |
| 2 | strrpos() | mb_strrpos() |
| 2 | substr() | mb_substr() |
| 2 | strtolower() | mb_strtolower() |
| 2 | strtoupper() | mb_strtoupper() |
| 2 | stripos() | mb_stripos() |
| 2 | strripos() | mb_strripos() |
| 2 | strstr() | mb_strstr() |
| 2 | stristr() | mb_stristr() |
| 2 | strrchr() | mb_strrchr() |
| 2 | substr_count() | mb_substr_count() |
| 4 | ereg() | mb_ereg() |
| 4 | eregi() | mb_eregi() |
| 4 | ereg_replace() | mb_ereg_replace() |
| 4 | eregi_replace() | mb_eregi_replace() |
| 4 | split() | mb_split() |
Note:
It is not recommended to use the function overloading option in the per-directory context, because it's not confirmed yet to be stable enough in a production environment and may lead to undefined behaviour.
Encodings of the following types are safely used with PHP.
A singlebyte encoding,
00h to
7fh.
A multibyte encoding,
00h to 7fh.
00h to
7fh in any of the compounded bytes
that represents a single character.
These are examples of character encodings that are unlikely to work with PHP.
JIS, SJIS, ISO-2022-JP, BIG-5
Although PHP scripts written in any of those encodings might not work,
especially in the case where encoded strings appear as identifiers
or literals in the script, you can almost avoid using these encodings
by setting up the mbstring's transparent encoding
filter function for incoming HTTP queries.
Note:
It's highly discouraged to use SJIS, BIG5, CP936, CP949 and GB18030 for the internal encoding unless you are familiar with the parser, the scanner and the character encoding.
Note:
If you are connecting to a database with PHP, it is recommended that you use the same character encoding for both the database and the
internal encodingfor ease of use and better performance.If you are using PostgreSQL, the character encoding used in the database and the one used in PHP may differ as it supports automatic character set conversion between the backend and the frontend.
Multibyte character encoding schemes and their related issues are fairly complicated, and are beyond the scope of this documentation. Please refer to the following URLs and other resources for further information regarding these topics.
Unicode materials
Japanese/Korean/Chinese character information
» https://resources.oreilly.com/examples/9781565922242/blob/master/doc/cjk.inf
(PHP 4 >= 4.4.3, PHP 5 >= 5.1.3, PHP 7)
mb_check_encoding — Check if strings are valid for the specified encoding
Checks if the specified byte stream is valid for the specified encoding.
If var is of type array, all keys and values are
validated recursively.
It is useful to prevent so-called "Invalid Encoding Attack".
varThe byte stream or array to check. If it is omitted, this function checks all the input from the beginning of the request.
encodingThe expected encoding.
Returns TRUE on success or FALSE on failure.
(PHP 7 >= 7.2.0)
mb_chr — Get a specific character
$cp
[, string $encoding
] ) : string
This function is currently not documented; only its argument list is available.
cp
encoding
Returns a specific character or FALSE on failure.
(PHP 4 >= 4.3.0, PHP 5, PHP 7)
mb_convert_case — Perform case folding on a string
$str
, int $mode
[, string $encoding = mb_internal_encoding()
] ) : string
Performs case folding on a string, converted in the way specified by
mode.
strThe string being converted.
mode
The mode of the conversion. It can be one of
MB_CASE_UPPER,
MB_CASE_LOWER,
MB_CASE_TITLE,
MB_CASE_FOLD,
MB_CASE_UPPER_SIMPLE,
MB_CASE_LOWER_SIMPLE,
MB_CASE_TITLE_SIMPLE,
MB_CASE_FOLD_SIMPLE.
encodingThe encoding
parameter is the character encoding. If it is omitted, the internal character
encoding value will be used.
A case folded version of string converted in the
way specified by mode.
By contrast to the standard case folding functions such as strtolower() and strtoupper(), case folding is performed on the basis of the Unicode character properties. Thus the behaviour of this function is not affected by locale settings and it can convert any characters that have 'alphabetic' property, such as A-umlaut (Ä).
For more information about the Unicode properties, please see » http://www.unicode.org/unicode/reports/tr21/.
| Version | Description |
|---|---|
| 7.3.0 |
Added support for
MB_CASE_FOLD,
MB_CASE_UPPER_SIMPLE,
MB_CASE_LOWER_SIMPLE,
MB_CASE_TITLE_SIMPLE, and
MB_CASE_FOLD_SIMPLE
as mode.
|
Example #1 mb_convert_case() example
<?php
$str = "mary had a Little lamb and she loved it so";
$str = mb_convert_case($str, MB_CASE_UPPER, "UTF-8");
echo $str; // Prints MARY HAD A LITTLE LAMB AND SHE LOVED IT SO
$str = mb_convert_case($str, MB_CASE_TITLE, "UTF-8");
echo $str; // Prints Mary Had A Little Lamb And She Loved It So
?>
Example #2 mb_convert_case() example with non-Latin UTF-8 text
<?php
$str = "Τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός";
$str = mb_convert_case($str, MB_CASE_UPPER, "UTF-8");
echo $str; // Prints ΤΆΧΙΣΤΗ ΑΛΏΠΗΞ ΒΑΦΉΣ ΨΗΜΈΝΗ ΓΗ, ΔΡΑΣΚΕΛΊΖΕΙ ΥΠΈΡ ΝΩΘΡΟΎ ΚΥΝΌΣ
$str = mb_convert_case($str, MB_CASE_TITLE, "UTF-8");
echo $str; // Prints Τάχιστη Αλώπηξ Βαφήσ Ψημένη Γη, Δρασκελίζει Υπέρ Νωθρού Κυνόσ
?>
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_convert_encoding — Convert character encoding
$val
, string $to_encoding
[, mixed $from_encoding = mb_internal_encoding()
] ) : mixed
Converts the character encoding of val
to to_encoding
from optionally from_encoding.
If val is an array, all its string values will be
converted recursively.
valto_encoding
The type of encoding that val is being converted to.
from_encoding
Is specified by character code names before conversion. It is either
an array, or a comma separated enumerated list.
If from_encoding is not specified, the internal
encoding will be used.
See supported encodings.
Example #1 mb_convert_encoding() example
<?php
/* Convert internal character encoding to SJIS */
$str = mb_convert_encoding($str, "SJIS");
/* Convert EUC-JP to UTF-7 */
$str = mb_convert_encoding($str, "UTF-7", "EUC-JP");
/* Auto detect encoding from JIS, eucjp-win, sjis-win, then convert str to UCS-2LE */
$str = mb_convert_encoding($str, "UCS-2LE", "JIS, eucjp-win, sjis-win");
/* "auto" is expanded to "ASCII,JIS,UTF-8,EUC-JP,SJIS" */
$str = mb_convert_encoding($str, "EUC-JP", "auto");
?>
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_convert_kana — Convert "kana" one from another ("zen-kaku", "han-kaku" and more)
$str
[, string $option = "KV"
[, string $encoding = mb_internal_encoding()
]] ) : string
Performs a "han-kaku" - "zen-kaku" conversion for string str.
This function is only useful for Japanese.
strThe string being converted.
optionThe conversion option.
Specify with a combination of following options.
| Option | Meaning |
|---|---|
r |
Convert "zen-kaku" alphabets to "han-kaku" |
R |
Convert "han-kaku" alphabets to "zen-kaku" |
n |
Convert "zen-kaku" numbers to "han-kaku" |
N |
Convert "han-kaku" numbers to "zen-kaku" |
a |
Convert "zen-kaku" alphabets and numbers to "han-kaku" |
A |
Convert "han-kaku" alphabets and numbers to "zen-kaku" (Characters included in "a", "A" options are U+0021 - U+007E excluding U+0022, U+0027, U+005C, U+007E) |
s |
Convert "zen-kaku" space to "han-kaku" (U+3000 -> U+0020) |
S |
Convert "han-kaku" space to "zen-kaku" (U+0020 -> U+3000) |
k |
Convert "zen-kaku kata-kana" to "han-kaku kata-kana" |
K |
Convert "han-kaku kata-kana" to "zen-kaku kata-kana" |
h |
Convert "zen-kaku hira-gana" to "han-kaku kata-kana" |
H |
Convert "han-kaku kata-kana" to "zen-kaku hira-gana" |
c |
Convert "zen-kaku kata-kana" to "zen-kaku hira-gana" |
C |
Convert "zen-kaku hira-gana" to "zen-kaku kata-kana" |
V |
Collapse voiced sound notation and convert them into a character. Use with "K","H" |
encodingThe encoding
parameter is the character encoding. If it is omitted, the internal character
encoding value will be used.
The converted string.
Example #1 mb_convert_kana() example
<?php
/* Convert all "kana" to "zen-kaku" "kata-kana" */
$str = mb_convert_kana($str, "KVC");
/* Convert "han-kaku" "kata-kana" to "zen-kaku" "kata-kana"
and "zen-kaku" alphanumeric to "han-kaku" */
$str = mb_convert_kana($str, "KVa");
?>
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_convert_variables — Convert character code in variable(s)
$to_encoding
, mixed $from_encoding
, mixed &$vars
[, mixed &$...
] ) : string
Converts
character encoding of variables vars in
encoding from_encoding to encoding
to_encoding.
mb_convert_variables() join strings in Array or Object to detect encoding, since encoding detection tends to fail for short strings. Therefore, it is impossible to mix encoding in single array or object.
to_encodingThe encoding that the string is being converted to.
from_encoding
from_encoding is specified as an array
or comma separated string, it tries to detect encoding from
from-coding. When from_encoding
is omitted, detect_order is used.
vars
vars is the reference to the
variable being converted. String, Array and Object are accepted.
mb_convert_variables() assumes all parameters
have the same encoding.
...
Additional vars.
The character encoding before conversion for success,
or FALSE for failure.
Example #1 mb_convert_variables() example
<?php
/* Convert variables $post1, $post2 to internal encoding */
$interenc = mb_internal_encoding();
$inputenc = mb_convert_variables($interenc, "ASCII,UTF-8,SJIS-win", $post1, $post2);
?>
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_decode_mimeheader — Decode string in MIME header field
$str
) : string
Decodes encoded-word string str in MIME header.
The decoded string in internal character encoding.
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_decode_numericentity — Decode HTML numeric string reference to character
$str
, array $convmap
[, string $encoding = mb_internal_encoding()
[, bool $is_hex = FALSE
]] ) : string
Convert numeric string reference of string
str in a specified block to character.
The converted string.
| Version | Description |
|---|---|
| 5.4.0 |
Added is_hex parameter.
|
Example #1 convmap example
<?php
$convmap = array (
int start_code1, int end_code1, int offset1, int mask1,
int start_code2, int end_code2, int offset2, int mask2,
........
int start_codeN, int end_codeN, int offsetN, int maskN );
// Specify Unicode value for start_codeN and end_codeN
// Add offsetN to value and take bit-wise 'AND' with maskN,
// then convert value to numeric string reference.
?>
Example #2 convmap example escapes JavaScript string
<?php
function escape_javascript_string($str) {
$map = [
1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,0,0, // 49
0,0,0,0,0,0,0,0,1,1,
1,1,1,1,1,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,1,1,1,1,1,1,0,0,0, // 99
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1, // 149
1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1, // 199
1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1, // 249
1,1,1,1,1,1,1, // 255
];
// Char encoding is UTF-8
$mblen = mb_strlen($str, 'UTF-8');
$utf32 = bin2hex(mb_convert_encoding($str, 'UTF-32', 'UTF-8'));
for ($i=0, $encoded=''; $i < $mblen; $i++) {
$u = substr($utf32, $i*8, 8);
$v = base_convert($u, 16, 10);
if ($v < 256 && $map[$v]) {
$encoded .= '\\x'.substr($u, 6,2);
} else if ($v == 2028) {
$encoded .= '\\u2028';
} else if ($v == 2029) {
$encoded .= '\\u2029';
} else {
$encoded .= mb_convert_encoding(hex2bin($u), 'UTF-8', 'UTF-32');
}
}
return $encoded;
}
// Test data
$convmap = [ 0x0, 0xffff, 0, 0xffff ];
$msg = '';
for ($i=0; $i < 1000; $i++) {
// chr() cannot generate correct UTF-8 data larger value than 128, use mb_decode_numericentity().
$msg .= mb_decode_numericentity('&#'.$i.';', $convmap, 'UTF-8');
}
// var_dump($msg);
var_dump(escape_javascript_string($msg));
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_detect_encoding — Detect character encoding
$str
[, mixed $encoding_list = mb_detect_order()
[, bool $strict = FALSE
]] ) : string
Detects character encoding in string str.
strThe string being detected.
encoding_list
encoding_list is list of character
encoding. Encoding order may be specified by array or comma
separated list string.
If encoding_list is omitted,
detect_order is used.
strict
strict specifies whether to use
the strict encoding detection or not.
Default is FALSE.
The detected character encoding or FALSE if the encoding cannot be
detected from the given string.
Example #1 mb_detect_encoding() example
<?php
/* Detect character encoding with current detect_order */
echo mb_detect_encoding($str);
/* "auto" is expanded according to mbstring.language */
echo mb_detect_encoding($str, "auto");
/* Specify encoding_list character encoding by comma separated list */
echo mb_detect_encoding($str, "JIS, eucjp-win, sjis-win");
/* Use array to specify encoding_list */
$ary[] = "ASCII";
$ary[] = "JIS";
$ary[] = "EUC-JP";
echo mb_detect_encoding($str, $ary);
?>
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_detect_order — Set/Get character encoding detection order
Sets the automatic character
encoding detection order to encoding_list.
encoding_list
encoding_list is an array or
comma separated list of character encoding. See supported encodings.
If encoding_list is omitted, it returns
the current character encoding detection order as array.
This setting affects mb_detect_encoding() and mb_send_mail().
mbstring currently implements the following
encoding detection filters. If there is an invalid byte sequence
for the following encodings, encoding detection will fail.
UTF-8, UTF-7,
ASCII,
EUC-JP,SJIS,
eucJP-win, SJIS-win,
JIS, ISO-2022-JP
For ISO-8859-*, mbstring
always detects as ISO-8859-*.
For UTF-16, UTF-32,
UCS2 and UCS4, encoding
detection will fail always.
When setting the encoding detection order, TRUE is returned on success or FALSE on failure.
When getting the encoding detection order, an ordered array of the encodings is returned.
Example #1 mb_detect_order() examples
<?php
/* Set detection order by enumerated list */
mb_detect_order("eucjp-win,sjis-win,UTF-8");
/* Set detection order by array */
$ary[] = "ASCII";
$ary[] = "JIS";
$ary[] = "EUC-JP";
mb_detect_order($ary);
/* Display current detection order */
echo implode(", ", mb_detect_order());
?>
Example #2 Example showing useless detect orders
; Always detect as ISO-8859-1 detect_order = ISO-8859-1, UTF-8 ; Always detect as UTF-8, since ASCII/UTF-7 values are ; valid for UTF-8 detect_order = UTF-8, ASCII, UTF-7
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_encode_mimeheader — Encode string for MIME header
$str
[, string $charset = mb_language()
[, string $transfer_encoding = "B"
[, string $linefeed = "\r\n"
[, int $indent = 0
]]]] ) : string
Encodes a given string
str by the MIME header encoding scheme.
strThe string being encoded. Its encoding should be same as mb_internal_encoding().
charset
charset specifies the name of the character set
in which str is represented in. The default value
is determined by the current NLS setting (mbstring.language).
transfer_encoding
transfer_encoding specifies the scheme of MIME
encoding. It should be either "B" (Base64) or
"Q" (Quoted-Printable). Falls back to
"B" if not given.
linefeed
linefeed specifies the EOL (end-of-line) marker
with which mb_encode_mimeheader() performs
line-folding (a » RFC term,
the act of breaking a line longer than a certain length into multiple
lines. The length is currently hard-coded to 74 characters).
Falls back to "\r\n" (CRLF) if not given.
indent
Indentation of the first line (number of characters in the header
before str).
A converted version of the string represented in ASCII.
Example #1 mb_encode_mimeheader() example
<?php
$name = ""; // kanji
$mbox = "kru";
$doma = "gtinn.mon";
$addr = mb_encode_mimeheader($name, "UTF-7", "Q") . " <" . $mbox . "@" . $doma . ">";
echo $addr;
?>
Note:
This function isn't designed to break lines at higher-level contextual break points (word boundaries, etc.). This behaviour may clutter up the original string with unexpected spaces.
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_encode_numericentity — Encode character to HTML numeric string reference
$str
, array $convmap
[, string $encoding = mb_internal_encoding()
[, bool $is_hex = FALSE
]] ) : string
Converts
specified character codes in string str
from character code to HTML numeric character reference.
strThe string being encoded.
convmap
convmap is array specifies code area to
convert.
encodingThe encoding
parameter is the character encoding. If it is omitted, the internal character
encoding value will be used.
is_hexWhether the returned entity reference should be in hexadecimal notation (otherwise it is in decimal notation).
The converted string.
| Version | Description |
|---|---|
| 5.4.0 |
Added is_hex parameter.
|
Example #1 convmap example
<?php
$convmap = array (
int start_code1, int end_code1, int offset1, int mask1,
int start_code2, int end_code2, int offset2, int mask2,
........
int start_codeN, int end_codeN, int offsetN, int maskN );
// Specify Unicode value for start_codeN and end_codeN
// Add offsetN to value and take bit-wise 'AND' with maskN, then
// it converts value to numeric string reference.
?>
Example #2 mb_encode_numericentity() example
<?php
/* Convert Left side of ISO-8859-1 to HTML numeric character reference */
$convmap = array(0x80, 0xff, 0, 0xff);
$str = mb_encode_numericentity($str, $convmap, "ISO-8859-1");
/* Convert user defined SJIS-win code in block 95-104 to numeric
string reference */
$convmap = array(
0xe000, 0xe03e, 0x1040, 0xffff,
0xe03f, 0xe0bb, 0x1041, 0xffff,
0xe0bc, 0xe0fa, 0x1084, 0xffff,
0xe0fb, 0xe177, 0x1085, 0xffff,
0xe178, 0xe1b6, 0x10c8, 0xffff,
0xe1b7, 0xe233, 0x10c9, 0xffff,
0xe234, 0xe272, 0x110c, 0xffff,
0xe273, 0xe2ef, 0x110d, 0xffff,
0xe2f0, 0xe32e, 0x1150, 0xffff,
0xe32f, 0xe3ab, 0x1151, 0xffff );
$str = mb_encode_numericentity($str, $convmap, "sjis-win");
?>
(PHP 5 >= 5.3.0, PHP 7)
mb_encoding_aliases — Get aliases of a known encoding type
$encoding
) : array
Returns an array of aliases for a known encoding type.
encodingThe encoding type being checked, for aliases.
Returns a numerically indexed array of encoding aliases on success,
or FALSE on failure
Emits an E_WARNING level error if
encoding is unknown.
Example #1 mb_encoding_aliases() example
<?php
$encoding = 'ASCII';
$known_encodings = mb_list_encodings();
if (in_array($encoding, $known_encodings)) {
$aliases = mb_encoding_aliases($encoding);
print_r($aliases);
} else {
echo "Unknown ($encoding) encoding.\n";
}
?>
The above example will output something similar to:
Array
(
[0] => ANSI_X3.4-1968
[1] => iso-ir-6
[2] => ANSI_X3.4-1986
[3] => ISO_646.irv:1991
[4] => US-ASCII
[5] => ISO646-US
[6] => us
[7] => IBM367
[8] => cp367
[9] => csASCII
)
(PHP 4 >= 4.2.0, PHP 5, PHP 7)
mb_ereg_match — Regular expression match for multibyte string
$pattern
, string $string
[, string $option = "msr"
] ) : boolA regular expression match for a multibyte string
patternThe regular expression pattern.
stringThe string being evaluated.
optionThe search option. See mb_regex_set_options() for explanation.
Returns TRUE if
string matches the regular expression
pattern, FALSE if not.
Note:
The internal encoding or the character encoding specified by mb_regex_encoding() will be used as the character encoding for this function.
(PHP 5 >= 5.4.1, PHP 7)
mb_ereg_replace_callback — Perform a regular expression search and replace with multibyte support using a callback
$pattern
, callable $callback
, string $string
[, string $option = "msr"
] ) : string
Scans string for matches to
pattern, then replaces the matched text
with the output of callback function.
The behavior of this function is almost identical to mb_ereg_replace(),
except for the fact that instead of
replacement parameter, one should specify a
callback.
patternThe regular expression pattern.
Multibyte characters may be used in pattern.
callback
A callback that will be called and passed an array of matched elements
in the subject string. The callback should
return the replacement string.
You'll often need the callback function
for a mb_ereg_replace_callback() in just one place.
In this case you can use an
anonymous function to
declare the callback within the call to
mb_ereg_replace_callback(). By doing it this way
you have all information for the call in one place and do not
clutter the function namespace with a callback function's name
not used anywhere else.
stringThe string being checked.
optionThe search option. See mb_regex_set_options() for explanation.
The resultant string on success, or FALSE on error.
Note:
The internal encoding or the character encoding specified by mb_regex_encoding() will be used as the character encoding for this function.
Example #1 mb_ereg_replace_callback() example
<?php
// this text was used in 2002
// we want to get this up to date for 2003
$text = "April fools day is 04/01/2002\n";
$text.= "Last christmas was 12/24/2001\n";
// the callback function
function next_year($matches)
{
// as usual: $matches[0] is the complete match
// $matches[1] the match for the first subpattern
// enclosed in '(...)' and so on
return $matches[1].($matches[2]+1);
}
echo mb_ereg_replace_callback(
"(\d{2}/\d{2}/)(\d{4})",
"next_year",
$text);
?>
The above example will output:
April fools day is 04/01/2003 Last christmas was 12/24/2002
Example #2 mb_ereg_replace_callback() using anonymous function supported in PHP 5.3.0 or later
<?php
// this text was used in 2002
// we want to get this up to date for 2003
$text = "April fools day is 04/01/2002\n";
$text.= "Last christmas was 12/24/2001\n";
echo mb_ereg_replace_callback(
"(\d{2}/\d{2}/)(\d{4})",
function ($matches) {
return $matches[1].($matches[2]+1);
},
$text);
?>
(PHP 4 >= 4.2.0, PHP 5, PHP 7)
mb_ereg_replace — Replace regular expression with multibyte support
$pattern
, string $replacement
, string $string
[, string $option = "msr"
] ) : string
Scans string for matches to
pattern, then replaces the matched text
with replacement
patternThe regular expression pattern.
Multibyte characters may be used in pattern.
replacementThe replacement text.
stringThe string being checked.
option
The resultant string on success, or FALSE on error.
| Version | Description |
|---|---|
| 7.1.0 |
The e modifier has been deprecated.
|
Note:
The internal encoding or the character encoding specified by mb_regex_encoding() will be used as the character encoding for this function.
Never use the e modifier when working on untrusted input. No automatic escaping will happen (as known from preg_replace()). Not taking care of this will most likely create remote code execution vulnerabilities in your application.
(PHP 4 >= 4.2.0, PHP 5, PHP 7)
mb_ereg_search_getpos — Returns start point for next regular expression match
Returns the start point for the next regular expression match.
This function has no parameters.
mb_ereg_search_getpos() returns the point to start regular expression match for mb_ereg_search(), mb_ereg_search_pos(), mb_ereg_search_regs(). The position is represented by bytes from the head of string.
Note:
The internal encoding or the character encoding specified by mb_regex_encoding() will be used as the character encoding for this function.
(PHP 4 >= 4.2.0, PHP 5, PHP 7)
mb_ereg_search_getregs — Retrieve the result from the last multibyte regular expression match
Retrieve the result from the last multibyte regular expression match
This function has no parameters.
An array
including the sub-string of matched part by last
mb_ereg_search(),
mb_ereg_search_pos(),
mb_ereg_search_regs(). If there are some
matches, the first element will have the matched sub-string, the
second element will have the first part grouped with brackets,
the third element will have the second part grouped with
brackets, and so on. It returns FALSE on error;
Note:
The internal encoding or the character encoding specified by mb_regex_encoding() will be used as the character encoding for this function.
(PHP 4 >= 4.2.0, PHP 5, PHP 7)
mb_ereg_search_init — Setup string and regular expression for a multibyte regular expression match
$string
[, string $pattern
[, string $option = "msr"
]] ) : bool
mb_ereg_search_init() sets
string and pattern
for a multibyte regular expression. These values are used for
mb_ereg_search(),
mb_ereg_search_pos(), and
mb_ereg_search_regs().
stringThe search string.
patternThe search pattern.
optionThe search option. See mb_regex_set_options() for explanation.
Returns TRUE on success or FALSE on failure.
Note:
The internal encoding or the character encoding specified by mb_regex_encoding() will be used as the character encoding for this function.
(PHP 4 >= 4.2.0, PHP 5, PHP 7)
mb_ereg_search_pos — Returns position and length of a matched part of the multibyte regular expression for a predefined multibyte string
$pattern
[, string $option = "ms"
]] ) : arrayReturns position and length of a matched part of the multibyte regular expression for a predefined multibyte string
The string for match is specified by mb_ereg_search_init(). If it is not specified, the previous one will be used.
patternThe search pattern.
optionThe search option. See mb_regex_set_options() for explanation.
An array containing two elements. The first element is the offset, in bytes, where the match begins relative to the start of the search string, and the second element is the length in bytes of the match.
If an error occurs, FALSE is returned.
Note:
The internal encoding or the character encoding specified by mb_regex_encoding() will be used as the character encoding for this function.
(PHP 4 >= 4.2.0, PHP 5, PHP 7)
mb_ereg_search_regs — Returns the matched part of a multibyte regular expression
$pattern
[, string $option = "ms"
]] ) : arrayReturns the matched part of a multibyte regular expression.
patternThe search pattern.
optionThe search option. See mb_regex_set_options() for explanation.
mb_ereg_search_regs() executes the multibyte
regular expression match, and if there are some matched part, it
returns an array including substring of matched part as first
element, the first grouped part with brackets as second element,
the second grouped part as third element, and so on.
It returns FALSE on error.
Note:
The internal encoding or the character encoding specified by mb_regex_encoding() will be used as the character encoding for this function.
(PHP 4 >= 4.2.0, PHP 5, PHP 7)
mb_ereg_search_setpos — Set start point of next regular expression match
$position
) : boolmb_ereg_search_setpos() sets the starting point of a match for mb_ereg_search().
positionThe position to set. If it is negative, it counts from the end of the string.
Returns TRUE on success or FALSE on failure.
| Version | Description |
|---|---|
| 7.1.0 |
Support for negative positions has been added.
|
Note:
The internal encoding or the character encoding specified by mb_regex_encoding() will be used as the character encoding for this function.
(PHP 4 >= 4.2.0, PHP 5, PHP 7)
mb_ereg_search — Multibyte regular expression match for predefined multibyte string
$pattern
[, string $option = "ms"
]] ) : boolPerforms a multibyte regular expression match for a predefined multibyte string.
patternThe search pattern.
optionThe search option. See mb_regex_set_options() for explanation.
mb_ereg_search() returns TRUE if the
multibyte string matches with the regular expression, or FALSE
otherwise. The string for matching is set by
mb_ereg_search_init(). If
pattern is not specified, the previous one
is used.
Note:
The internal encoding or the character encoding specified by mb_regex_encoding() will be used as the character encoding for this function.
(PHP 4 >= 4.2.0, PHP 5, PHP 7)
mb_ereg — Regular expression match with multibyte support
$pattern
, string $string
[, array &$regs
] ) : intExecutes the regular expression match with multibyte support.
patternThe search pattern.
stringThe search string.
regs
If matches are found for parenthesized substrings of
pattern and the function is called with the
third argument regs, the matches will be stored
in the elements of the array regs.
If no matches are found, regs is set to an empty
array.
$regs[1] will contain the substring which starts at the first left parenthesis; $regs[2] will contain the substring starting at the second, and so on. $regs[0] will contain a copy of the complete string matched.
Returns the byte length of the matched string if a match for
pattern was found in string,
or FALSE if no matches were found or an error occurred.
If the optional parameter regs was not passed or
the length of the matched string is 0, this function returns 1.
| Version | Description |
|---|---|
| 7.1.0 |
mb_ereg() will now set regs to
an empty array, if nothing matched. Formerly,
regs was not modified in that case.
|
Note:
The internal encoding or the character encoding specified by mb_regex_encoding() will be used as the character encoding for this function.
(PHP 4 >= 4.2.0, PHP 5, PHP 7)
mb_eregi_replace — Replace regular expression with multibyte support ignoring case
$pattern
, string $replace
, string $string
[, string $option = "msri"
] ) : string
Scans string for matches to
pattern, then replaces the matched text
with replacement.
patternThe regular expression pattern. Multibyte characters may be used. The case will be ignored.
replaceThe replacement text.
stringThe searched string.
option
The resultant string or FALSE on error.
| Version | Description |
|---|---|
| 7.1.0 |
The e modifier has been deprecated.
|
Note:
The internal encoding or the character encoding specified by mb_regex_encoding() will be used as the character encoding for this function.
Never use the e modifier when working on untrusted input. No automatic escaping will happen (as known from preg_replace()). Not taking care of this will most likely create remote code execution vulnerabilities in your application.
(PHP 4 >= 4.2.0, PHP 5, PHP 7)
mb_eregi — Regular expression match ignoring case with multibyte support
$pattern
, string $string
[, array &$regs
] ) : intExecutes the case insensitive regular expression match with multibyte support.
patternThe regular expression pattern.
stringThe string being searched.
regs
If matches are found for parenthesized substrings of
pattern and the function is called with the
third argument regs, the matches will be stored
in the elements of the array regs.
If no matches are found, regs is set to an empty
array.
$regs[1] will contain the substring which starts at the first left parenthesis; $regs[2] will contain the substring starting at the second, and so on. $regs[0] will contain a copy of the complete string matched.
Returns the byte length of the matched string if a match for
pattern was found in string,
or FALSE if no matches were found or an error occurred.
If the optional parameter regs was not passed or
the length of the matched string is 0, this function returns 1.
| Version | Description |
|---|---|
| 7.1.0 |
mb_eregi() will now set regs to
an empty array, if nothing matched. Formerly,
regs was not modified in that case.
|
Note:
The internal encoding or the character encoding specified by mb_regex_encoding() will be used as the character encoding for this function.
(PHP 4 >= 4.2.0, PHP 5, PHP 7)
mb_get_info — Get internal settings of mbstring
mb_get_info() returns the internal setting parameters of mbstring.
type
If type isn't specified or is specified to
"all", an array having the elements "internal_encoding",
"http_output", "http_input", "func_overload", "mail_charset",
"mail_header_encoding", "mail_body_encoding" will be returned.
If type is specified as "http_output",
"http_input", "internal_encoding", "func_overload",
the specified setting parameter will be returned.
An array of type information if type
is not specified, otherwise a specific type.
| Version | Description |
|---|---|
| 5.3.0 | The entry "http_output_conv_mimetypes" was made available. |
| 5.1.3 | The entries "mail_charset", "mail_header_encoding", and "mail_body_encoding" were made available. |
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_http_input — Detect HTTP input character encoding
Detects the HTTP input character encoding.
typeInput string specifies the input type. "G" for GET, "P" for POST, "C" for COOKIE, "S" for string, "L" for list, and "I" for the whole list (will return array). If type is omitted, it returns the last input type processed.
The character encoding name, as per the type.
If mb_http_input() does not process specified
HTTP input, it returns FALSE.
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_http_output — Set/Get HTTP output character encoding
Set/Get the HTTP output character encoding.
Output after this function is called will be converted from the set internal encoding to encoding.
encoding
If encoding is set,
mb_http_output() sets the HTTP output character
encoding to encoding.
If encoding is omitted,
mb_http_output() returns the current HTTP output
character encoding.
If encoding is omitted,
mb_http_output() returns the current HTTP output
character encoding. Otherwise,
Returns TRUE on success or FALSE on failure.
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_internal_encoding — Set/Get internal character encoding
Set/Get the internal character encoding
encoding
encoding is the character encoding name
used for the HTTP input character encoding conversion, HTTP output
character encoding conversion, and the default character encoding
for string functions defined by the mbstring module.
You should notice that the internal encoding is totally different from the one for multibyte regex.
If encoding is set, then
Returns TRUE on success or FALSE on failure.
In this case, the character encoding for multibyte regex is NOT changed.
If encoding is omitted, then
the current character encoding name is returned.
Example #1 mb_internal_encoding() example
<?php
/* Set internal character encoding to UTF-8 */
mb_internal_encoding("UTF-8");
/* Display current internal character encoding */
echo mb_internal_encoding();
?>
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_language — Set/Get current language
$language
) : boolSet/Get the current language.
languageUsed for encoding e-mail messages. The valid languages are listed in the following table. mb_send_mail() uses this setting to encode e-mail.
| Language | Charset | Encoding | Notes |
|---|---|---|---|
| German/de | ISO-8859-15 | Quoted-Printable | |
| English/en | ISO-8859-1 | Quoted-Printable | |
| Armenian/hy | ArmSCII-8 | Quoted-Printable | |
| Japanese/ja | ISO-2022-JP | BASE64 | |
| Korean/ko | ISO-2022-KR | BASE64 | |
| neutral | UTF-8 | BASE64 | |
| Russian/ru | KOI8-R | Quoted-Printable | |
| Turkish/tr | ISO-8859-9 | Quoted-Printable | Available as of PHP 5.2.0 |
| Ukrainian/ua | KOI8-U | Quoted-Printable | Available as of PHP 5.3.0 |
| uni | UTF-8 | BASE64 | |
| Simplified Chinese/zh-cn | HZ | BASE64 | |
| Traditional Chinese/zh-tw | BIG-5 | BASE64 |
If language is set and
language is valid, it returns
TRUE. Otherwise, it returns FALSE.
When language is omitted, it returns the language
name as a string.
(PHP 5, PHP 7)
mb_list_encodings — Returns an array of all supported encodings
Returns an array containing all supported encodings.
This function has no parameters.
Returns a numerically indexed array.
This function does not emit any errors.
Example #1 mb_list_encodings() example
<?php
print_r(mb_list_encodings());
?>
The above example will output something similar to:
Array
(
[0] => pass
[1] => auto
[2] => wchar
[3] => byte2be
[4] => byte2le
[5] => byte4be
[6] => byte4le
[7] => BASE64
[8] => UUENCODE
[9] => HTML-ENTITIES
[10] => Quoted-Printable
[11] => 7bit
[12] => 8bit
[13] => UCS-4
[14] => UCS-4BE
[15] => UCS-4LE
[16] => UCS-2
[17] => UCS-2BE
[18] => UCS-2LE
[19] => UTF-32
[20] => UTF-32BE
[21] => UTF-32LE
[22] => UTF-16
[23] => UTF-16BE
[24] => UTF-16LE
[25] => UTF-8
[26] => UTF-7
[27] => UTF7-IMAP
[28] => ASCII
[29] => EUC-JP
[30] => SJIS
[31] => eucJP-win
[32] => SJIS-win
[33] => JIS
[34] => ISO-2022-JP
[35] => Windows-1252
[36] => ISO-8859-1
[37] => ISO-8859-2
[38] => ISO-8859-3
[39] => ISO-8859-4
[40] => ISO-8859-5
[41] => ISO-8859-6
[42] => ISO-8859-7
[43] => ISO-8859-8
[44] => ISO-8859-9
[45] => ISO-8859-10
[46] => ISO-8859-13
[47] => ISO-8859-14
[48] => ISO-8859-15
[49] => EUC-CN
[50] => CP936
[51] => HZ
[52] => EUC-TW
[53] => BIG-5
[54] => EUC-KR
[55] => UHC
[56] => ISO-2022-KR
[57] => Windows-1251
[58] => CP866
[59] => KOI8-R
)
(PHP 7 >= 7.2.0)
mb_ord — Get code point of character
$str
[, string $encoding
] ) : int
This function is currently not documented; only its argument list is available.
str
encoding
Returns a code point of character or FALSE on failure.
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_output_handler — Callback function converts character encoding in output buffer
$contents
, int $status
) : stringmb_output_handler() is ob_start() callback function. mb_output_handler() converts characters in the output buffer from internal character encoding to HTTP output character encoding.
contentsThe contents of the output buffer.
statusThe status of the output buffer.
The converted string.
Example #1 mb_output_handler() example
<?php
mb_http_output("UTF-8");
ob_start("mb_output_handler");
?>
Note:
If you want to output binary data, such as an image, a Content-Type: header must be set using header() before any binary data is sent to the client (e.g. header("Content-Type: image/png")). If Content-Type: header is sent, output character encoding conversion will not be performed.
Note that if 'Content-Type: text/*' is sent, the content body is regarded as text; conversion will take place.
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_parse_str — Parse GET/POST/COOKIE data and set global variable
$encoded_string
, array &$result
) : bool
Parses GET/POST/COOKIE data and
sets global variables. Since PHP does not provide raw POST/COOKIE
data, it can only be used for GET data for now. It parses URL
encoded data, detects encoding, converts coding to internal
encoding and set values to the result array or
global variables.
encoded_stringThe URL encoded data.
resultAn array containing decoded and character encoded converted values.
Returns TRUE on success or FALSE on failure.
| Version | Description |
|---|---|
| 8.0.0 | The second parameter was no longer optional. |
| 7.2.0 | Calling mb_parse_str() without the second parameter was deprecated. |
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_preferred_mime_name — Get MIME charset string
$encoding
) : stringGet a MIME charset string for a specific encoding.
encodingThe encoding being checked.
The MIME charset string for character encoding
encoding.
Example #1 mb_preferred_mime_name() example
<?php
$outputenc = "sjis-win";
mb_http_output($outputenc);
ob_start("mb_output_handler");
header("Content-Type: text/html; charset=" . mb_preferred_mime_name($outputenc));
?>
(PHP 4 >= 4.2.0, PHP 5, PHP 7)
mb_regex_encoding — Set/Get character encoding for multibyte regex
Set/Get character encoding for a multibyte regex.
encodingThe encoding
parameter is the character encoding. If it is omitted, the internal character
encoding value will be used.
If encoding is set, then
Returns TRUE on success or FALSE on failure.
In this case, the internal character encoding is NOT changed.
If encoding is omitted, then
the current character encoding name for a multibyte regex is returned.
| Version | Description |
|---|---|
| 5.6.0 | Default encoding is changed to UTF-8. It was EUC-JP Previously. |
(PHP 4 >= 4.3.0, PHP 5, PHP 7)
mb_regex_set_options — Set/Get the default options for mbregex functions
$options = mb_regex_set_options()
] ) : string
Sets the default options described by options
for multibyte regex functions.
optionsThe options to set. This is a string where each character is an option. To set a mode, the mode character must be the last one set, however there can only be set one mode but multiple options.
| Option | Meaning |
|---|---|
| i | Ambiguity match on |
| x | Enables extended pattern form |
| m | '.' matches with newlines |
| s | '^' -> '\A', '$' -> '\Z' |
| p | Same as both the m and s options |
| l | Finds longest matches |
| n | Ignores empty matches |
| e | eval() resulting code |
| Mode | Meaning |
|---|---|
| j | Java (Sun java.util.regex) |
| u | GNU regex |
| g | grep |
| c | Emacs |
| r | Ruby |
| z | Perl |
| b | POSIX Basic regex |
| d | POSIX Extended regex |
The string that describes the current options is returned.
(PHP 7 >= 7.2.0)
mb_scrub — Description
$str
[, string $encoding
] ) : string
This function is currently not documented; only its argument list is available.
str
encoding
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_send_mail — Send encoded mail
$to
, string $subject
, string $message
[, mixed $additional_headers = NULL
[, string $additional_parameter = NULL
]] ) : boolSends email. Headers and messages are converted and encoded according to the mb_language() setting. It's a wrapper function for mail(), so see also mail() for details.
to
The mail addresses being sent to. Multiple
recipients may be specified by putting a comma between each
address in to.
This parameter is not automatically encoded.
subjectThe subject of the mail.
messageThe message of the mail.
additional_headers (optional)String or array to be inserted at the end of the email header.
This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n). Validate parameter not to be injected unwanted headers by attackers.
If an array is passed, its keys are the header names and its values are the respective header values.
Note:
When sending mail, the mail must contain a
Fromheader. This can be set with theadditional_headersparameter, or a default can be set in php.ini.Failing to do this will result in an error message similar to
Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing. TheFromheader sets alsoReturn-Pathunder Windows.
Note:
If messages are not received, try using a LF (\n) only. Some Unix mail transfer agents (most notably » qmail) replace LF by CRLF automatically (which leads to doubling CR if CRLF is used). This should be a last resort, as it does not comply with » RFC 2822.
additional_parameter
additional_parameter is a MTA command line
parameter. It is useful when setting the correct Return-Path
header when using sendmail.
This parameter is escaped by escapeshellcmd() internally to prevent command execution. escapeshellcmd() prevents command execution, but allows to add additional parameters. For security reason, this parameter should be validated.
Since escapeshellcmd() is applied automatically, some characters that are allowed as email addresses by internet RFCs cannot be used. Programs that are required to use these characters mail() cannot be used.
The user that the webserver runs as should be added as a trusted user to the sendmail configuration to prevent a 'X-Warning' header from being added to the message when the envelope sender (-f) is set using this method. For sendmail users, this file is /etc/mail/trusted-users.
Returns TRUE on success or FALSE on failure.
(PHP 4 >= 4.2.0, PHP 5, PHP 7)
mb_split — Split multibyte string using regular expression
$pattern
, string $string
[, int $limit = -1
] ) : array
Split a multibyte
string using regular expression
pattern and returns the result as an
array.
patternThe regular expression pattern.
stringThe string being split.
limitlimit is specified,
it will be split in limit elements as
maximum.
The result as an array, or FALSE on failure.
Note:
The character encoding specified by mb_regex_encoding() will be used as the character encoding for this function by default.
(PHP 7 >= 7.4.0)
mb_str_split — Given a multibyte string, return an array of its characters
$string
[, int $split_length = 1
[, string $encoding = mb_internal_encoding()
]] ) : array
This function will return an array of strings, it is a version of str_split() with support for encodings of variable character size as well as fixed-size encodings of 1,2 or 4 byte characters.
If the split_length parameter is specified, the string is broken down into chunks of the specified length in characters (not bytes).
The encoding parameter can be optionally specified and it is good practice to do so.
stringThe string to split into characters or chunks.
split_lengthIf specified, each element of the returned array will be composed of multiple characters instead of a single character.
encodingThe encoding
parameter is the character encoding. If it is omitted, the internal character
encoding value will be used.
A string specifying one of the supported encodings.
mb_str_split() returns an array of strings, or FALSE on failure.
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_strcut — Get part of string
$str
, int $start
[, int $length = NULL
[, string $encoding = mb_internal_encoding()
]] ) : stringmb_strcut() extracts a substring from a string similarly to mb_substr(), but operates on bytes instead of characters. If the cut position happens to be between two bytes of a multi-byte character, the cut is performed starting from the first byte of that character. This is also the difference to the substr() function, which would simply cut the string between the bytes and thus result in a malformed byte sequence.
strThe string being cut.
start
If start is non-negative, the returned string
will start at the start'th byte position in
str, counting from zero. For instance,
in the string 'abcdef', the byte at
position 0 is 'a', the
byte at position 2 is
'c', and so forth.
If start is negative, the returned string
will start at the start'th byte
counting back from the end of str. However, if the
magnitude of a negative start is greater than the
length of the string, the returned portion will start from the beginning of
str.
length
Length in bytes. If omitted or NULL
is passed, extract all bytes to the end of the string.
If length is negative, the returned string will
end at the length'th byte counting back from the
end of str. However, if the magnitude of a negative
length is greater than the number of characters
after the start position, an empty string will
be returned.
encodingThe encoding
parameter is the character encoding. If it is omitted, the internal character
encoding value will be used.
mb_strcut() returns the portion of
str specified by the
start and
length parameters.
| Version | Description |
|---|---|
| 5.4.8 |
Passing NULL as length
extracts all bytes to the end of the string. Prior to this version
NULL was treated the same as 0.
|
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_strimwidth — Get truncated string with specified width
$str
, int $start
, int $width
[, string $trimmarker = ""
[, string $encoding = mb_internal_encoding()
]] ) : string
Truncates string str to specified width.
strThe string being decoded.
startThe start position offset. Number of characters from the beginning of string (first character is 0), or if start is negative, number of characters from the end of the string.
widthThe width of the desired trim. Negative widths count from the end of the string.
trimmarkerA string that is added to the end of string when string is truncated.
encodingThe encoding
parameter is the character encoding. If it is omitted, the internal character
encoding value will be used.
The truncated string. If trimmarker is set,
trimmarker replaces the last chars to match the width.
| Version | Description |
|---|---|
| 7.1.0 |
Support for negative starts and widths has been added.
|
Example #1 mb_strimwidth() example
<?php
echo mb_strimwidth("Hello World", 0, 10, "...");
// output: "Hello W..."
?>
(PHP 5 >= 5.2.0, PHP 7)
mb_stripos — Finds position of first occurrence of a string within another, case insensitive
$haystack
, string $needle
[, int $offset = 0
[, string $encoding = mb_internal_encoding()
]] ) : int
mb_stripos() returns the numeric position of
the first occurrence of needle in the
haystack string.
Unlike mb_strpos(),
mb_stripos() is case-insensitive.
If needle is not found, it returns FALSE.
haystack
The string from which to get the position of the first occurrence
of needle
needle
The string to find in haystack
offset
The position in haystack
to start searching.
A negative offset counts from the end of the string.
encodingCharacter encoding name to use. If it is omitted, internal character encoding is used.
Return the numeric position of the first occurrence of
needle in the haystack
string, or FALSE if needle is not found.
| Version | Description |
|---|---|
| 7.1.0 |
Support for negative offsets has been added.
|
(PHP 5 >= 5.2.0, PHP 7)
mb_stristr — Finds first occurrence of a string within another, case insensitive
$haystack
, string $needle
[, bool $before_needle = FALSE
[, string $encoding = mb_internal_encoding()
]] ) : string
mb_stristr() finds the first occurrence of
needle in haystack
and returns the portion of haystack.
Unlike mb_strstr(),
mb_stristr() is case-insensitive.
If needle is not found, it returns FALSE.
haystack
The string from which to get the first occurrence
of needle
needle
The string to find in haystack
before_needle
Determines which portion of haystack
this function returns.
If set to TRUE, it returns all of haystack
from the beginning to the first occurrence of needle (excluding needle).
If set to FALSE, it returns all of haystack
from the first occurrence of needle to the end (including needle).
encodingCharacter encoding name to use. If it is omitted, internal character encoding is used.
Returns the portion of haystack,
or FALSE if needle is not found.
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_strlen — Get string length
$str
[, string $encoding = mb_internal_encoding()
] ) : intGets the length of a string.
strThe string being checked for length.
encodingThe encoding
parameter is the character encoding. If it is omitted, the internal character
encoding value will be used.
Returns the number of characters in
string str having character encoding
encoding. A multi-byte character is
counted as 1.
If the encoding is unknown, an error of level
E_WARNING is generated.
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_strpos — Find position of first occurrence of string in a string
$haystack
, string $needle
[, int $offset = 0
[, string $encoding = mb_internal_encoding()
]] ) : intFinds position of the first occurrence of a string in a string.
Performs a multi-byte safe strpos() operation based on number of characters. The first character's position is 0, the second character position is 1, and so on.
haystackThe string being checked.
needle
The string to find in haystack. In contrast
with strpos(), numeric values are not applied
as the ordinal value of a character.
offsetThe search offset. If it is not specified, 0 is used. A negative offset counts from the end of the string.
encodingThe encoding
parameter is the character encoding. If it is omitted, the internal character
encoding value will be used.
Returns the numeric position of
the first occurrence of needle in the
haystack string. If
needle is not found, it returns FALSE.
| Version | Description |
|---|---|
| 7.1.0 |
Support for negative offsets has been added.
|
(PHP 5 >= 5.2.0, PHP 7)
mb_strrchr — Finds the last occurrence of a character in a string within another
$haystack
, string $needle
[, bool $part = FALSE
[, string $encoding = mb_internal_encoding()
]] ) : string
mb_strrchr() finds the last occurrence of
needle in haystack
and returns the portion of haystack.
If needle is not found, it returns FALSE.
haystack
The string from which to get the last occurrence
of needle
needle
The string to find in haystack
part
Determines which portion of haystack
this function returns.
If set to TRUE, it returns all of haystack
from the beginning to the last occurrence of needle.
If set to FALSE, it returns all of haystack
from the last occurrence of needle to the end,
encodingCharacter encoding name to use. If it is omitted, internal character encoding is used.
Returns the portion of haystack.
or FALSE if needle is not found.
(PHP 5 >= 5.2.0, PHP 7)
mb_strrichr — Finds the last occurrence of a character in a string within another, case insensitive
$haystack
, string $needle
[, bool $part = FALSE
[, string $encoding = mb_internal_encoding()
]] ) : string
mb_strrichr() finds the last occurrence of
needle in haystack
and returns the portion of haystack. Unlike
mb_strrchr(), mb_strrichr() is
case-insensitive.
If needle is not found, it returns FALSE.
haystack
The string from which to get the last occurrence
of needle
needle
The string to find in haystack
part
Determines which portion of haystack
this function returns.
If set to TRUE, it returns all of haystack
from the beginning to the last occurrence of needle.
If set to FALSE, it returns all of haystack
from the last occurrence of needle to the end,
encodingCharacter encoding name to use. If it is omitted, internal character encoding is used.
Returns the portion of haystack.
or FALSE if needle is not found.
(PHP 5 >= 5.2.0, PHP 7)
mb_strripos — Finds position of last occurrence of a string within another, case insensitive
$haystack
, string $needle
[, int $offset = 0
[, string $encoding = mb_internal_encoding()
]] ) : int
mb_strripos() performs multi-byte safe
strripos() operation based on
number of characters. needle position is
counted from the beginning of
haystack. First character's position is
0. Second character position is 1.
Unlike mb_strrpos(),
mb_strripos() is case-insensitive.
haystack
The string from which to get the position of the last occurrence
of needle
needle
The string to find in haystack
offset
The position in haystack
to start searching
encodingCharacter encoding name to use. If it is omitted, internal character encoding is used.
Return the numeric position of
the last occurrence of needle in the
haystack string, or FALSE
if needle is not found.
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_strrpos — Find position of last occurrence of a string in a string
$haystack
, string $needle
[, int $offset = 0
[, string $encoding = mb_internal_encoding()
]] ) : int
Performs a multibyte safe
strrpos() operation based on the
number of characters. needle position is
counted from the beginning of
haystack. First character's position is
0. Second character position is 1.
haystack
The string being checked, for the last occurrence
of needle
needle
The string to find in haystack.
offsetencodingThe encoding
parameter is the character encoding. If it is omitted, the internal character
encoding value will be used.
Returns the numeric position of
the last occurrence of needle in the
haystack string. If
needle is not found, it returns FALSE.
| Version | Description |
|---|---|
| 5.2.0 | Added the optional parameter offset. |
Note: The
encodingparameter was moved from the third position to the fourth in PHP 5.2.0. For backward compatibility,encodingcan be specified as the third parameter, but doing so is deprecated and will be removed in the future.
(PHP 5 >= 5.2.0, PHP 7)
mb_strstr — Finds first occurrence of a string within another
$haystack
, string $needle
[, bool $before_needle = FALSE
[, string $encoding = mb_internal_encoding()
]] ) : string
mb_strstr() finds the first occurrence of
needle in haystack
and returns the portion of haystack.
If needle is not found, it returns FALSE.
haystack
The string from which to get the first occurrence
of needle
needle
The string to find in haystack
before_needle
Determines which portion of haystack
this function returns.
If set to TRUE, it returns all of haystack
from the beginning to the first occurrence of needle (excluding needle).
If set to FALSE, it returns all of haystack
from the first occurrence of needle to the end (including needle).
encodingCharacter encoding name to use. If it is omitted, internal character encoding is used.
Returns the portion of haystack,
or FALSE if needle is not found.
(PHP 4 >= 4.3.0, PHP 5, PHP 7)
mb_strtolower — Make a string lowercase
$str
[, string $encoding = mb_internal_encoding()
] ) : string
Returns str
with all alphabetic characters converted to lowercase.
strThe string being lowercased.
encodingThe encoding
parameter is the character encoding. If it is omitted, the internal character
encoding value will be used.
str with all alphabetic characters converted to lowercase.
For more information about the Unicode properties, please see » http://www.unicode.org/unicode/reports/tr21/.
By contrast to strtolower(), 'alphabetic' is determined by the Unicode character properties. Thus the behaviour of this function is not affected by locale settings and it can convert any characters that have 'alphabetic' property, such as A-umlaut (Ä).
Example #1 mb_strtolower() example
<?php
$str = "Mary Had A Little Lamb and She LOVED It So";
$str = mb_strtolower($str);
echo $str; // Prints mary had a little lamb and she loved it so
?>
Example #2 mb_strtolower() example with non-Latin UTF-8 text
<?php
$str = "Τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός";
$str = mb_strtolower($str, 'UTF-8');
echo $str; // Prints τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός
?>
(PHP 4 >= 4.3.0, PHP 5, PHP 7)
mb_strtoupper — Make a string uppercase
$str
[, string $encoding = mb_internal_encoding()
] ) : string
Returns str
with all alphabetic characters converted to uppercase.
strThe string being uppercased.
encodingThe encoding
parameter is the character encoding. If it is omitted, the internal character
encoding value will be used.
str with all alphabetic characters converted to uppercase.
For more information about the Unicode properties, please see » http://www.unicode.org/unicode/reports/tr21/.
By contrast to strtoupper(), 'alphabetic' is determined by the Unicode character properties. Thus the behaviour of this function is not affected by locale settings and it can convert any characters that have 'alphabetic' property, such as a-umlaut (ä).
Example #1 mb_strtoupper() example
<?php
$str = "Mary Had A Little Lamb and She LOVED It So";
$str = mb_strtoupper($str);
echo $str; // Prints MARY HAD A LITTLE LAMB AND SHE LOVED IT SO
?>
Example #2 mb_strtoupper() example with non-Latin UTF-8 text
<?php
$str = "Τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός";
$str = mb_strtoupper($str, 'UTF-8');
echo $str; // Prints ΤΆΧΙΣΤΗ ΑΛΏΠΗΞ ΒΑΦΉΣ ΨΗΜΈΝΗ ΓΗ, ΔΡΑΣΚΕΛΊΖΕΙ ΥΠΈΡ ΝΩΘΡΟΎ ΚΥΝΌΣ
?>
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_strwidth — Return width of string
$str
[, string $encoding = mb_internal_encoding()
] ) : int
Returns the width of string str,
where halfwidth characters count as 1, and fullwidth
characters count as 2.
The fullwidth characters are:
U+1100-U+115F,
U+11A3-U+11A7,
U+11FA-U+11FF,
U+2329-U+232A,
U+2E80-U+2E99,
U+2E9B-U+2EF3,
U+2F00-U+2FD5,
U+2FF0-U+2FFB,
U+3000-U+303E,
U+3041-U+3096,
U+3099-U+30FF,
U+3105-U+312D,
U+3131-U+318E,
U+3190-U+31BA,
U+31C0-U+31E3,
U+31F0-U+321E,
U+3220-U+3247,
U+3250-U+32FE,
U+3300-U+4DBF,
U+4E00-U+A48C,
U+A490-U+A4C6,
U+A960-U+A97C,
U+AC00-U+D7A3,
U+D7B0-U+D7C6,
U+D7CB-U+D7FB,
U+F900-U+FAFF,
U+FE10-U+FE19,
U+FE30-U+FE52,
U+FE54-U+FE66,
U+FE68-U+FE6B,
U+FF01-U+FF60,
U+FFE0-U+FFE6,
U+1B000-U+1B001,
U+1F200-U+1F202,
U+1F210-U+1F23A,
U+1F240-U+1F248,
U+1F250-U+1F251,
U+20000-U+2FFFD,
U+30000-U+3FFFD.
All other characters are halfwidth characters.
strThe string being decoded.
encodingThe encoding
parameter is the character encoding. If it is omitted, the internal character
encoding value will be used.
The width of string str.
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_substitute_character — Set/Get substitution character
Specifies a substitution character when input character encoding is invalid
or character code does not exist in output character
encoding. Invalid characters may be substituted NULL (no output),
string or integer value (Unicode character code value).
This setting affects mb_convert_encoding(), mb_convert_variables(), mb_output_handler(), and mb_send_mail().
If substchar is set, it returns TRUE for success,
otherwise returns FALSE.
If substchar is not set, it returns the current
setting.
Example #1 mb_substitute_character() example
<?php
/* Set with Unicode U+3013 (GETA MARK) */
mb_substitute_character(0x3013);
/* Set hex format */
mb_substitute_character("long");
/* Display current setting */
echo mb_substitute_character();
?>
(PHP 4 >= 4.3.0, PHP 5, PHP 7)
mb_substr_count — Count the number of substring occurrences
$haystack
, string $needle
[, string $encoding = mb_internal_encoding()
] ) : int
Counts the number of times the
needle substring occurs in the
haystack string.
The number of times the
needle substring occurs in the
haystack string.
Example #1 mb_substr_count() example
<?php
echo mb_substr_count("This is a test", "is"); // prints out 2
?>
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_substr — Get part of string
$str
, int $start
[, int $length = NULL
[, string $encoding = mb_internal_encoding()
]] ) : string
Performs a multi-byte safe
substr() operation based on
number of characters. Position is
counted from the beginning of
str. First character's position is
0. Second character position is 1, and so on.
strThe string to extract the substring from.
start
If start is non-negative, the returned string
will start at the start'th position in
str, counting from zero. For instance,
in the string 'abcdef', the character at
position 0 is 'a', the
character at position 2 is
'c', and so forth.
If start is negative, the returned string
will start at the start'th character
from the end of str.
length
Maximum number of characters to use from str. If
omitted or NULL is passed, extract all characters to
the end of the string.
encodingThe encoding
parameter is the character encoding. If it is omitted, the internal character
encoding value will be used.
mb_substr() returns the portion of
str specified by the
start and
length parameters.
| Version | Description |
|---|---|
| 5.4.8 |
Passing NULL as length
extracts all characters to the end of the string. Prior to this version
NULL was treated the same as 0.
|
These functions allow you to check the spelling of a word and offer suggestions.
To compile PHP with pspell support, you need the aspell library, available from » http://aspell.net/.
If you have the libraries needed add the --with-pspell[=dir] option when compiling PHP.
Note: Note to Win32 Users
In order for this extension to work, there are DLL files that must be available to the Windows system PATH. For information on how to do this, see the FAQ entitled "How do I add my PHP directory to the PATH on Windows". Although copying DLL files from the PHP folder into the Windows system directory also works (because the system directory is by default in the system's PATH), this is not recommended. This extension requires the following files to be in the PATH: aspell-15.dll from the bin folder of the aspell installation.
Win32 support requires at least aspell version 0.50.
This extension has no configuration directives defined in php.ini.
This extension has no resource types defined.
The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.
(PHP 4 >= 4.0.2, PHP 5, PHP 7)
pspell_add_to_personal — Add the word to a personal wordlist
$dictionary_link
, string $word
) : boolpspell_add_to_personal() adds a word to the personal wordlist. If you used pspell_new_config() with pspell_config_personal() to open the dictionary, you can save the wordlist later with pspell_save_wordlist().
dictionary_link
wordThe added word.
Returns TRUE on success or FALSE on failure.
Example #1 pspell_add_to_personal()
<?php
$pspell_config = pspell_config_create("en");
pspell_config_personal($pspell_config, "/var/dictionaries/custom.pws");
$pspell_link = pspell_new_config($pspell_config);
pspell_add_to_personal($pspell_link, "Vlad");
pspell_save_wordlist($pspell_link);
?>
Note:
This function will not work unless you have pspell .11.2 and aspell .32.5 or later.
(PHP 4 >= 4.0.2, PHP 5, PHP 7)
pspell_add_to_session — Add the word to the wordlist in the current session
$dictionary_link
, string $word
) : boolpspell_add_to_session() adds a word to the wordlist associated with the current session. It is very similar to pspell_add_to_personal()
dictionary_link
wordThe added word.
Returns TRUE on success or FALSE on failure.
(PHP 4 >= 4.0.2, PHP 5, PHP 7)
pspell_check — Check a word
$dictionary_link
, string $word
) : boolpspell_check() checks the spelling of a word.
dictionary_link
wordThe tested word.
Returns TRUE if the spelling is correct, FALSE if not.
Example #1 pspell_check() Example
<?php
$pspell_link = pspell_new("en");
if (pspell_check($pspell_link, "testt")) {
echo "This is a valid spelling";
} else {
echo "Sorry, wrong spelling";
}
?>
(PHP 4 >= 4.0.2, PHP 5, PHP 7)
pspell_clear_session — Clear the current session
$dictionary_link
) : boolpspell_clear_session() clears the current session. The current wordlist becomes blank, and, for example, if you try to save it with pspell_save_wordlist(), nothing happens.
dictionary_link
Returns TRUE on success or FALSE on failure.
Example #1 pspell_add_to_personal() Example
<?php
$pspell_config = pspell_config_create("en");
pspell_config_personal($pspell_config, "/var/dictionaries/custom.pws");
$pspell_link = pspell_new_config($pspell_config);
pspell_add_to_personal($pspell_link, "Vlad");
pspell_clear_session($pspell_link);
pspell_save_wordlist($pspell_link); //"Vlad" will not be saved
?>
(PHP 4 >= 4.0.2, PHP 5, PHP 7)
pspell_config_create — Create a config used to open a dictionary
$language
[, string $spelling
[, string $jargon
[, string $encoding
]]] ) : intCreate a config used to open a dictionary.
pspell_config_create() has a very similar syntax to pspell_new(). In fact, using pspell_config_create() immediately followed by pspell_new_config() will produce the exact same result. However, after creating a new config, you can also use pspell_config_*() functions before calling pspell_new_config() to take advantage of some advanced functionality.
For more information and examples, check out inline manual pspell website:» http://aspell.net/.
languageThe language parameter is the language code which consists of the two letter ISO 639 language code and an optional two letter ISO 3166 country code after a dash or underscore.
spellingThe spelling parameter is the requested spelling for languages with more than one spelling such as English. Known values are 'american', 'british', and 'canadian'.
jargonThe jargon parameter contains extra information to distinguish two different words lists that have the same language and spelling parameters.
encodingThe encoding parameter is the encoding that words are expected to be in. Valid values are 'utf-8', 'iso8859-*', 'koi8-r', 'viscii', 'cp1252', 'machine unsigned 16', 'machine unsigned 32'. This parameter is largely untested, so be careful when using.
Returns a pspell config identifier, or FALSE on error.
Example #1 pspell_config_create()
<?php
$pspell_config = pspell_config_create("en");
pspell_config_personal($pspell_config, "/var/dictionaries/custom.pws");
pspell_config_repl($pspell_config, "/var/dictionaries/custom.repl");
$pspell_link = pspell_new_personal($pspell_config, "en");
?>
(PHP 5, PHP 7)
pspell_config_data_dir — Location of language data files
$conf
, string $directory
) : bool
This function is currently not documented; only its argument list is available.
Returns TRUE on success or FALSE on failure.
(PHP 5, PHP 7)
pspell_config_dict_dir — Location of the main word list
$conf
, string $directory
) : bool
This function is currently not documented; only its argument list is available.
Returns TRUE on success or FALSE on failure.
(PHP 4 >= 4.0.2, PHP 5, PHP 7)
pspell_config_ignore — Ignore words less than N characters long
$dictionary_link
, int $n
) : boolpspell_config_ignore() should be used on a config before calling pspell_new_config(). This function allows short words to be skipped by the spell checker.
dictionary_link
n
Words less than n characters will be skipped.
Returns TRUE on success or FALSE on failure.
Example #1 pspell_config_ignore()
<?php
$pspell_config = pspell_config_create("en");
pspell_config_ignore($pspell_config, 5);
$pspell_link = pspell_new_config($pspell_config);
pspell_check($pspell_link, "abcd"); //will not result in an error
?>
(PHP 4 >= 4.0.2, PHP 5, PHP 7)
pspell_config_mode — Change the mode number of suggestions returned
$dictionary_link
, int $mode
) : boolpspell_config_mode() should be used on a config before calling pspell_new_config(). This function determines how many suggestions will be returned by pspell_suggest().
dictionary_link
modeThe mode parameter is the mode in which spellchecker will work. There are several modes available:
PSPELL_FAST - Fast mode (least number of
suggestions)
PSPELL_NORMAL - Normal mode (more suggestions)
PSPELL_BAD_SPELLERS - Slow mode (a lot of
suggestions)
Returns TRUE on success or FALSE on failure.
Example #1 pspell_config_mode() Example
<?php
$pspell_config = pspell_config_create("en");
pspell_config_mode($pspell_config, PSPELL_FAST);
$pspell_link = pspell_new_config($pspell_config);
pspell_check($pspell_link, "thecat");
?>
(PHP 4 >= 4.0.2, PHP 5, PHP 7)
pspell_config_personal — Set a file that contains personal wordlist
$dictionary_link
, string $file
) : boolSet a file that contains personal wordlist. The personal wordlist will be loaded and used in addition to the standard one after you call pspell_new_config(). The file is also the file where pspell_save_wordlist() will save personal wordlist to.
pspell_config_personal() should be used on a config before calling pspell_new_config().
dictionary_link
fileThe personal wordlist. If the file does not exist, it will be created. The file should be writable by whoever PHP runs as (e.g. nobody).
Returns TRUE on success or FALSE on failure.
Example #1 pspell_config_personal()
<?php
$pspell_config = pspell_config_create("en");
pspell_config_personal($pspell_config, "/var/dictionaries/custom.pws");
$pspell_link = pspell_new_config($pspell_config);
pspell_check($pspell_link, "thecat");
?>
Note:
This function will not work unless you have pspell .11.2 and aspell .32.5 or later.
(PHP 4 >= 4.0.2, PHP 5, PHP 7)
pspell_config_repl — Set a file that contains replacement pairs
$dictionary_link
, string $file
) : boolSet a file that contains replacement pairs.
The replacement pairs improve the quality of the spellchecker. When a word is misspelled, and a proper suggestion was not found in the list, pspell_store_replacement() can be used to store a replacement pair and then pspell_save_wordlist() to save the wordlist along with the replacement pairs.
pspell_config_repl() should be used on a config before calling pspell_new_config().
dictionary_link
fileThe file should be writable by whoever PHP runs as (e.g. nobody).
Returns TRUE on success or FALSE on failure.
Example #1 pspell_config_repl()
<?php
$pspell_config = pspell_config_create("en");
pspell_config_personal($pspell_config, "/var/dictionaries/custom.pws");
pspell_config_repl($pspell_config, "/var/dictionaries/custom.repl");
$pspell_link = pspell_new_config($pspell_config);
pspell_check($pspell_link, "thecat");
?>
Note:
This function will not work unless you have pspell .11.2 and aspell .32.5 or later.
(PHP 4 >= 4.0.2, PHP 5, PHP 7)
pspell_config_runtogether — Consider run-together words as valid compounds
$dictionary_link
, bool $flag
) : boolThis function determines whether run-together words will be treated as legal compounds. That is, "thecat" will be a legal compound, although there should be a space between the two words. Changing this setting only affects the results returned by pspell_check(); pspell_suggest() will still return suggestions.
pspell_config_runtogether() should be used on a config before calling pspell_new_config().
dictionary_link
flag
TRUE if run-together words should be treated as legal compounds,
FALSE otherwise.
Returns TRUE on success or FALSE on failure.
Example #1 pspell_config_runtogether()
<?php
$pspell_config = pspell_config_create("en");
pspell_config_runtogether($pspell_config, true);
$pspell_link = pspell_new_config($pspell_config);
pspell_check($pspell_link, "thecat");
?>
(PHP 4 >= 4.0.2, PHP 5, PHP 7)
pspell_config_save_repl — Determine whether to save a replacement pairs list along with the wordlist
$dictionary_link
, bool $flag
) : boolpspell_config_save_repl() determines whether pspell_save_wordlist() will save the replacement pairs along with the wordlist. Usually there is no need to use this function because if pspell_config_repl() is used, the replacement pairs will be saved by pspell_save_wordlist() anyway, and if it is not, the replacement pairs will not be saved.
pspell_config_save_repl() should be used on a config before calling pspell_new_config().
dictionary_link
flag
TRUE if replacement pairs should be saved, FALSE otherwise.
Returns TRUE on success or FALSE on failure.
Note:
This function will not work unless you have pspell .11.2 and aspell .32.5 or later.
(PHP 4 >= 4.0.2, PHP 5, PHP 7)
pspell_new_config — Load a new dictionary with settings based on a given config
$config
) : intpspell_new_config() opens up a new dictionary with settings specified in a config, created with pspell_config_create() and modified with pspell_config_*() functions. This method provides you with the most flexibility and has all the functionality provided by pspell_new() and pspell_new_personal().
config
The config parameter is the one returned by
pspell_config_create() when the config was created.
Returns a dictionary link identifier on success, or FALSE on failure.
Example #1 pspell_new_config()
<?php
$pspell_config = pspell_config_create("en");
pspell_config_personal($pspell_config, "/var/dictionaries/custom.pws");
pspell_config_repl($pspell_config, "/var/dictionaries/custom.repl");
$pspell_link = pspell_new_config($pspell_config);
?>
(PHP 4 >= 4.0.2, PHP 5, PHP 7)
pspell_new_personal — Load a new dictionary with personal wordlist
$personal
, string $language
[, string $spelling
[, string $jargon
[, string $encoding
[, int $mode = 0
]]]] ) : intpspell_new_personal() opens up a new dictionary with a personal wordlist. The wordlist can be modified and saved with pspell_save_wordlist(), if desired. However, the replacement pairs are not saved. In order to save replacement pairs, you should create a config using pspell_config_create(), set the personal wordlist file with pspell_config_personal(), set the file for replacement pairs with pspell_config_repl(), and open a new dictionary with pspell_new_config().
For more information and examples, check out inline manual pspell website:» http://aspell.net/.
personalThe file where words added to the personal list will be stored. It should be an absolute filename beginning with '/' because otherwise it will be relative to $HOME, which is "/root" for most systems, and is probably not what you want.
languageThe language code which consists of the two letter ISO 639 language code and an optional two letter ISO 3166 country code after a dash or underscore.
spellingThe requested spelling for languages with more than one spelling such as English. Known values are 'american', 'british', and 'canadian'.
jargonExtra information to distinguish two different words lists that have the same language and spelling parameters.
encoding
The encoding that words are expected to be in. Valid values are
utf-8, iso8859-*,
koi8-r, viscii,
cp1252, machine unsigned 16,
machine unsigned 32.
modeThe mode in which spellchecker will work. There are several modes available:
PSPELL_FAST - Fast mode (least number of
suggestions)
PSPELL_NORMAL - Normal mode (more suggestions)
PSPELL_BAD_SPELLERS - Slow mode (a lot of
suggestions)
PSPELL_RUN_TOGETHER - Consider run-together words
as legal compounds. That is, "thecat" will be a legal compound,
although there should be a space between the two words. Changing this
setting only affects the results returned by
pspell_check(); pspell_suggest()
will still return suggestions.
PSPELL_FAST,
PSPELL_NORMAL and
PSPELL_BAD_SPELLERS are mutually exclusive, so you
should select only one of them.
Returns the dictionary link identifier for use in other pspell functions.
Example #1 pspell_new_personal()
<?php
$pspell_link = pspell_new_personal ("/var/dictionaries/custom.pws",
"en", "", "", "", PSPELL_FAST|PSPELL_RUN_TOGETHER);
?>
(PHP 4 >= 4.0.2, PHP 5, PHP 7)
pspell_new — Load a new dictionary
$language
[, string $spelling
[, string $jargon
[, string $encoding
[, int $mode = 0
]]]] ) : intpspell_new() opens up a new dictionary and returns the dictionary link identifier for use in other pspell functions.
For more information and examples, check out inline manual pspell website:» http://aspell.net/.
languageThe language parameter is the language code which consists of the two letter ISO 639 language code and an optional two letter ISO 3166 country code after a dash or underscore.
spellingThe spelling parameter is the requested spelling for languages with more than one spelling such as English. Known values are 'american', 'british', and 'canadian'.
jargonThe jargon parameter contains extra information to distinguish two different words lists that have the same language and spelling parameters.
encodingThe encoding parameter is the encoding that words are expected to be in. Valid values are 'utf-8', 'iso8859-*', 'koi8-r', 'viscii', 'cp1252', 'machine unsigned 16', 'machine unsigned 32'. This parameter is largely untested, so be careful when using.
modeThe mode parameter is the mode in which spellchecker will work. There are several modes available:
PSPELL_FAST - Fast mode (least number of
suggestions)
PSPELL_NORMAL - Normal mode (more suggestions)
PSPELL_BAD_SPELLERS - Slow mode (a lot of
suggestions)
PSPELL_RUN_TOGETHER - Consider run-together words
as legal compounds. That is, "thecat" will be a legal compound,
although there should be a space between the two words. Changing this
setting only affects the results returned by
pspell_check(); pspell_suggest()
will still return suggestions.
PSPELL_FAST,
PSPELL_NORMAL and
PSPELL_BAD_SPELLERS are mutually exclusive, so you
should select only one of them.
Returns the dictionary link identifier on success or FALSE on failure.
Example #1 pspell_new()
<?php
$pspell_link = pspell_new("en", "", "", "",
(PSPELL_FAST|PSPELL_RUN_TOGETHER));
?>
(PHP 4 >= 4.0.2, PHP 5, PHP 7)
pspell_save_wordlist — Save the personal wordlist to a file
$dictionary_link
) : boolpspell_save_wordlist() saves the personal wordlist from the current session. The location of files to be saved specified with pspell_config_personal() and (optionally) pspell_config_repl().
Returns TRUE on success or FALSE on failure.
Example #1 pspell_add_to_personal()
<?php
$pspell_config = pspell_config_create("en");
pspell_config_personal($pspell_config, "/tmp/dicts/newdict");
$pspell_link = pspell_new_config($pspell_config);
pspell_add_to_personal($pspell_link, "Vlad");
pspell_save_wordlist($pspell_link);
?>
Note:
This function will not work unless you have pspell .11.2 and aspell .32.5 or later.
(PHP 4 >= 4.0.2, PHP 5, PHP 7)
pspell_store_replacement — Store a replacement pair for a word
$dictionary_link
, string $misspelled
, string $correct
) : boolpspell_store_replacement() stores a replacement pair for a word, so that replacement can be returned by pspell_suggest() later. In order to be able to take advantage of this function, you have to use pspell_new_personal() to open the dictionary. In order to permanently save the replacement pair, you have to use pspell_config_personal() and pspell_config_repl() to set the path where to save your custom wordlists, and then use pspell_save_wordlist() for the changes to be written to disk.
dictionary_linkA dictionary link identifier, opened with pspell_new_personal()
misspelledThe misspelled word.
correct
The fixed spelling for the misspelled word.
Returns TRUE on success or FALSE on failure.
Example #1 pspell_store_replacement()
<?php
$pspell_config = pspell_config_create("en");
pspell_config_personal($pspell_config, "/var/dictionaries/custom.pws");
pspell_config_repl($pspell_config, "/var/dictionaries/custom.repl");
$pspell_link = pspell_new_config($pspell_config);
pspell_store_replacement($pspell_link, $misspelled, $correct);
pspell_save_wordlist($pspell_link);
?>
Note:
This function will not work unless you have pspell .11.2 and aspell .32.5 or later.
(PHP 4 >= 4.0.2, PHP 5, PHP 7)
pspell_suggest — Suggest spellings of a word
$dictionary_link
, string $word
) : arraypspell_suggest() returns an array of possible spellings for the given word.
dictionary_link
wordThe tested word.
Returns an array of possible spellings.
Example #1 pspell_suggest() example
<?php
$pspell_link = pspell_new("en");
if (!pspell_check($pspell_link, "testt")) {
$suggestions = pspell_suggest($pspell_link, "testt");
foreach ($suggestions as $suggestion) {
echo "Possible spelling: $suggestion<br />";
}
}
?>
This module contains an interface to the GNU Recode library. The GNU Recode library converts files between various coded character sets and surface encodings. When this cannot be achieved exactly, it may get rid of the offending characters or fall back on approximations. The library recognises or produces nearly 150 different character sets and is able to convert files between almost any pair. Most » RFC 1345 character sets are supported.
Note: This extension is unbundled and moved to » PECL as of PHP 7.4.0. Consider to use the Multibyte String or iconv extensions instead.
Note: This extension is not available on Windows platforms.
You must have GNU Recode 3.5 or higher installed on your system. You can download the package from » http://directory.fsf.org/All_GNU_Packages/recode.html.
This extension has been moved to the » PECL repository and is no longer bundled with PHP as of PHP 7.4.0
Information for installing this PECL extension may be found in the manual chapter titled Installation of PECL extensions. Additional information such as new releases, downloads, source files, maintainer information, and a CHANGELOG, can be located here: » https://pecl.php.net/package/recode.
To be able to use the functions defined in this module you must compile your PHP interpreter using the --with-recode[=DIR] option.
Crashes and startup problems of PHP may be encountered
when loading the recode as extension after loading any extension of mysql or imap. Loading the recode before those
extension has proved to fix the problem. This is due a technical problem
that both the c-client library used by imap and recode have their own
hash_lookup() function and both mysql and recode have
their own hash_insert function.
This extension has no configuration directives defined in php.ini.
This extension has no resource types defined.
This extension has no constants defined.
(PHP 4, PHP 5, PHP 7 < 7.4.0)
recode_file — Recode from file to file according to recode request
$request
, resource $input
, resource $output
) : bool
Recode the file referenced by file handle
input into the file referenced by file
handle output according to the recode
request.
Returns FALSE, if unable to comply, TRUE otherwise.
Example #1 Basic recode_file() example
<?php
$input = fopen('input.txt', 'r');
$output = fopen('output.txt', 'w');
recode_file("us..flat", $input, $output);
?>
This function does not currently process file handles referencing remote files (URLs). Both file handles must refer to local files.
(PHP 4, PHP 5, PHP 7 < 7.4.0)
recode_string — Recode a string according to a recode request
$request
, string $string
) : string
Recode the string string according to
the recode request request.
Returns the recoded string or FALSE, if unable to
perform the recode request.
Example #1 Basic recode_string() example
<?php
echo recode_string("us..flat", "The following character has a diacritical mark: á");
?>
A simple recode request may be "lat1..iso646-de".
This function is an alias of: recode_string().
Cairo is a native PHP extension to create and modify graphics using the Cairo Graphics Library.
The Cairo Graphics Library is a 2D library written in C with support for multiple output devices. Currently supported output targets include the X Window System, Quartz, Win32, image buffers, PostScript, PDF, and SVG file output. Experimental backends include OpenGL (through glitz), XCB, BeOS, OS/2, and DirectFB. The library also has support for two types of text manipulation and layout. The "toy" API provides demo quality support, and the glyphs API, although full-featured, works best with a helper library such as pango. Font backend support includes FreeType, Quartz, Win32, and User fonts.
There are two types of computer graphics, vector and raster. Raster graphics are the representation of images as an array of pixels. Vector graphics use geometrical primitives such as points, lines, curves or polygons to represent images. The primitives are created using mathematical equations. The Cairo Graphics Library takes a vector approach to graphics, allowing smaller size, infinite zooming, and moving, scaling and rotating without degrading image quality.
Operations in the cairo graphics library including stroking and filling cubic Bézier splines, transforming and compositing translucent images, and antialiased text rendering. All drawing operations can be transformed by any affine transformation (scale, rotation, shear, and others) This is very similar to drawing operations for PostScript and PDF drawing.
The Cairo PHP Extension aims to provide support for all officially supported font backends and surface backends, as well as expose all available functionality in cairo to PHP users.
Cairo is only available for PHP 5.2+ and PHP 5.3+ The extension also requires the cairo graphics library version 1.4 or higher. The cairo graphics library uses an even and odd numbering scheme to denote stable and unstable library versions. Both unstable and stable versions can be used with the extension, but conditional support for new features is determined by the stable version below the unstable version in use. The latest cairo release can be found at » http://cairographics.org/.
The binary files used for the windows compiles can be found at » http://cairographics.org/download/ along with the project files used to create them.
Information for installing this PECL extension may be found in the manual chapter titled Installation of PECL extensions. Additional information such as new releases, downloads, source files, maintainer information, and a CHANGELOG, can be located here: » https://pecl.php.net/package/cairo.
A DLL for this PECL extension is currently unavailable. See also the building on Windows section.
Notes specific to installation on Windows
Binary builds of the extension can be found at » http://cairographics.org/download/. Download the correct zip file, place php_cairo.dll in the extensions directory, and enable it via the php.ini file in use. Please be sure the PHP minor version (5.2, 5.3) match, the thread safety (Thread Safe TS or Non-Thread Safe NTS), the architecture (x86 or x64), and the compiler version (VC6 or VC9) match or the extension will not load.
This extension has no configuration directives defined in php.ini.
This extension has no resource types defined.
The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.
CAIRO_STATUS_SUCCESS
(integer)
CAIRO_STATUS_NO_MEMORY
(integer)
CAIRO_STATUS_INVALID_RESTORE
(integer)
CAIRO_STATUS_INVALID_POP_GROUP
(integer)
CAIRO_STATUS_NO_CURRENT_POINT
(integer)
CAIRO_STATUS_INVALID_MATRIX
(integer)
CAIRO_STATUS_INVALID_STATUS
(integer)
CAIRO_STATUS_NULL_POINTER
(integer)
CAIRO_STATUS_INVALID_STRING
(integer)
CAIRO_STATUS_INVALID_PATH_DATA
(integer)
CAIRO_STATUS_READ_ERROR
(integer)
CAIRO_STATUS_WRITE_ERROR
(integer)
CAIRO_STATUS_SURFACE_FINISHED
(integer)
CAIRO_STATUS_SURFACE_TYPE_MISMATCH
(integer)
CAIRO_STATUS_PATTERN_TYPE_MISMATCH
(integer)
CAIRO_STATUS_INVALID_CONTENT
(integer)
CAIRO_STATUS_INVALID_FORMAT
(integer)
CAIRO_STATUS_INVALID_VISUAL
(integer)
CAIRO_STATUS_FILE_NOT_FOUND
(integer)
CAIRO_STATUS_INVALID_DASH
(integer)
CAIRO_STATUS_INVALID_DSC_COMMENT
(integer)
CAIRO_STATUS_INVALID_INDEX
(integer)
CAIRO_STATUS_CLIP_NOT_REPRESENTABLE
(integer)
CAIRO_STATUS_TEMP_FILE_ERROR
(integer)
CAIRO_STATUS_INVALID_STRIDE
(integer)
CAIRO_ANTIALIAS_DEFAULT
(integer)
CAIRO_ANTIALIAS_NONE
(integer)
CAIRO_ANTIALIAS_GRAY
(integer)
CAIRO_ANTIALIAS_SUBPIXEL
(integer)
CAIRO_SUBPIXEL_ORDER_DEFAULT
(integer)
CAIRO_SUBPIXEL_ORDER_RGB
(integer)
CAIRO_SUBPIXEL_ORDER_BGR
(integer)
CAIRO_SUBPIXEL_ORDER_VRGB
(integer)
CAIRO_SUBPIXEL_ORDER_VBGR
(integer)
CAIRO_FILL_RULE_WINDING
(integer)
CAIRO_FILL_RULE_EVEN_ODD
(integer)
CAIRO_LINE_CAP_BUTT
(integer)
CAIRO_LINE_CAP_ROUND
(integer)
CAIRO_LINE_CAP_SQUARE
(integer)
CAIRO_LINE_JOIN_MITER
(integer)
CAIRO_LINE_JOIN_ROUND
(integer)
CAIRO_LINE_JOIN_BEVEL
(integer)
CAIRO_OPERATOR_CLEAR
(integer)
CAIRO_OPERATOR_SOURCE
(integer)
CAIRO_OPERATOR_OVER
(integer)
CAIRO_OPERATOR_IN
(integer)
CAIRO_OPERATOR_OUT
(integer)
CAIRO_OPERATOR_ATOP
(integer)
CAIRO_OPERATOR_DEST
(integer)
CAIRO_OPERATOR_DEST_OVER
(integer)
CAIRO_OPERATOR_DEST_IN
(integer)
CAIRO_OPERATOR_DEST_OUT
(integer)
CAIRO_OPERATOR_DEST_ATOP
(integer)
CAIRO_OPERATOR_XOR
(integer)
CAIRO_OPERATOR_ADD
(integer)
CAIRO_OPERATOR_SATURATE
(integer)
CAIRO_PATTERN_TYPE_SOLID
(integer)
CAIRO_PATTERN_TYPE_SURFACE
(integer)
CAIRO_PATTERN_TYPE_LINEAR
(integer)
CAIRO_PATTERN_TYPE_RADIAL
(integer)
CAIRO_EXTEND_NONE
(integer)
CAIRO_EXTEND_REPEAT
(integer)
CAIRO_EXTEND_REFLECT
(integer)
CAIRO_EXTEND_PAD
(integer)
CAIRO_FILTER_FAST
(integer)
CAIRO_FILTER_GOOD
(integer)
CAIRO_FILTER_BEST
(integer)
CAIRO_FILTER_NEAREST
(integer)
CAIRO_FILTER_BILINEAR
(integer)
CAIRO_FILTER_GAUSSIAN
(integer)
CAIRO_HINT_STYLE_DEFAULT
(integer)
CAIRO_HINT_STYLE_NONE
(integer)
CAIRO_HINT_STYLE_SLIGHT
(integer)
CAIRO_HINT_STYLE_MEDIUM
(integer)
CAIRO_HINT_STYLE_FULL
(integer)
CAIRO_HINT_METRICS_DEFAULT
(integer)
CAIRO_HINT_METRICS_OFF
(integer)
CAIRO_HINT_METRICS_ON
(integer)
CAIRO_FONT_TYPE_TOY
(integer)
CAIRO_FONT_TYPE_FT
(integer)
CAIRO_FONT_TYPE_WIN32
(integer)
CAIRO_FONT_TYPE_QUARTZ
(integer)
CAIRO_FONT_SLANT_NORMAL
(integer)
CAIRO_FONT_SLANT_ITALIC
(integer)
CAIRO_FONT_SLANT_OBLIQUE
(integer)
CAIRO_FONT_WEIGHT_NORMAL
(integer)
CAIRO_FONT_WEIGHT_BOLD
(integer)
CAIRO_CONTENT_COLOR
(integer)
CAIRO_CONTENT_ALPHA
(integer)
CAIRO_CONTENT_COLOR_ALPHA
(integer)
CAIRO_SURFACE_TYPE_IMAGE
(integer)
CAIRO_SURFACE_TYPE_PDF
(integer)
CAIRO_SURFACE_TYPE_PS
(integer)
CAIRO_SURFACE_TYPE_XLIB
(integer)
CAIRO_SURFACE_TYPE_XCB
(integer)
CAIRO_SURFACE_TYPE_GLITZ
(integer)
CAIRO_SURFACE_TYPE_QUARTZ
(integer)
CAIRO_SURFACE_TYPE_WIN32
(integer)
CAIRO_SURFACE_TYPE_BEOS
(integer)
CAIRO_SURFACE_TYPE_DIRECTFB
(integer)
CAIRO_SURFACE_TYPE_SVG
(integer)
CAIRO_SURFACE_TYPE_OS2
(integer)
CAIRO_SURFACE_TYPE_WIN32_PRINTING
(integer)
CAIRO_SURFACE_TYPE_QUARTZ_IMAGE
(integer)
CAIRO_FORMAT_ARGB32
(integer)
CAIRO_FORMAT_RGB24
(integer)
CAIRO_FORMAT_A8
(integer)
CAIRO_FORMAT_A1
(integer)
CAIRO_PS_LEVEL_2
(integer)
CAIRO_PS_LEVEL_3
(integer)
CAIRO_SVG_VERSION_1_1
(integer)
CAIRO_SVG_VERSION_1_2
(integer)
Description here...
Example #1 Cairo Example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_create — Returns a new CairoContext object on the requested surface
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_create() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_font_options_create — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_font_options_create() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_font_options_equal — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
optionsDescription...
otherDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_font_options_equal() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_font_options_get_antialias — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
optionsDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_font_options_get_antialias() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_font_options_get_hint_metrics — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
optionsDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_font_options_get_hint_metrics() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_font_options_get_hint_style — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
optionsDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_font_options_get_hint_style() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_font_options_get_subpixel_order — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
optionsDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_font_options_get_subpixel_order() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_font_options_hash — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
optionsDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_font_options_hash() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_font_options_merge — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
optionsDescription...
otherDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_font_options_merge() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_font_options_set_antialias — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
optionsDescription...
antialiasDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_font_options_set_antialias() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_font_options_set_hint_metrics — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
optionsDescription...
hint_metricsDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_font_options_set_hint_metrics() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_font_options_set_hint_style — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
optionsDescription...
hint_styleDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_font_options_set_hint_style() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_font_options_set_subpixel_order — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
optionsDescription...
subpixel_orderDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_font_options_set_subpixel_order() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_font_options_status — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
optionsDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_font_options_status() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_format_stride_for_width — Description
$format
, int $width
) : intThe function description goes here.
This function is currently not documented; only its argument list is available.
formatDescription...
widthDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_format_stride_for_width() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_image_surface_create_for_data — Description
$data
, int $format
, int $width
, int $height
[, int $stride = -1
] ) : CairoImageSurfaceThe function description goes here.
This function is currently not documented; only its argument list is available.
dataDescription...
formatDescription...
widthDescription...
heightDescription...
strideDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_image_surface_create_for_data() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_image_surface_create_from_png — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
fileDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_image_surface_create_from_png() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_image_surface_create — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
formatDescription...
widthDescription...
heightDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_image_surface_create() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_image_surface_get_data — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_image_surface_get_data() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_image_surface_get_format — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_image_surface_get_format() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_image_surface_get_height — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_image_surface_get_height() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_image_surface_get_stride — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_image_surface_get_stride() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_image_surface_get_width — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_image_surface_get_width() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_matrix_create_scale — Alias of CairoMatrix::initScale()
This function is an alias of: CairoMatrix::initScale().
This function alias is deprecated and only exists for backwards compatibility reasons. The use of this function is not recommended, as it may be removed from PHP in the future.
(PECL cairo >= 0.1.0)
cairo_matrix_create_translate — Alias of CairoMatrix::initTranslate()
This function is an alias of: CairoMatrix::initTranslate().
This function alias is deprecated and only exists for backwards compatibility reasons. The use of this function is not recommended, as it may be removed from PHP in the future.
(PECL cairo >= 0.1.0)
cairo_matrix_invert — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
matrixDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_matrix_invert() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_matrix_multiply — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
matrix1Description...
matrix2Description...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_matrix_multiply() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_matrix_transform_distance — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
matrixDescription...
dxDescription...
dyDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_matrix_transform_distance() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_matrix_transform_point — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
matrixDescription...
dxDescription...
dyDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_matrix_transform_point() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_matrix_translate — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
matrixDescription...
txDescription...
tyDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_matrix_translate() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pattern_add_color_stop_rgb — Description
$pattern
, float $offset
, float $red
, float $green
, float $blue
) : voidThe function description goes here.
This function is currently not documented; only its argument list is available.
patternDescription...
offsetDescription...
redDescription...
greenDescription...
blueDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pattern_add_color_stop_rgb() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pattern_add_color_stop_rgba — Description
$pattern
, float $offset
, float $red
, float $green
, float $blue
, float $alpha
) : voidThe function description goes here.
This function is currently not documented; only its argument list is available.
patternDescription...
offsetDescription...
redDescription...
greenDescription...
blueDescription...
alphaDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pattern_add_color_stop_rgba() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pattern_create_for_surface — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pattern_create_for_surface() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pattern_create_linear — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
x0Description...
y0Description...
x1Description...
y1Description...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pattern_create_linear() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pattern_create_radial — Description
$x0
, float $y0
, float $r0
, float $x1
, float $y1
, float $r1
) : CairoPatternThe function description goes here.
This function is currently not documented; only its argument list is available.
x0Description...
y0Description...
r0Description...
x1Description...
y1Description...
r1Description...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pattern_create_radial() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pattern_create_rgb — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
redDescription...
greenDescription...
blueDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pattern_create_rgb() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pattern_create_rgba — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
redDescription...
greenDescription...
blueDescription...
alphaDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pattern_create_rgba() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pattern_get_color_stop_count — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
patternDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pattern_get_color_stop_count() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pattern_get_color_stop_rgba — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
patternDescription...
indexDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pattern_get_color_stop_rgba() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pattern_get_extend — Description
$pattern
) : intThe function description goes here.
This function is currently not documented; only its argument list is available.
patternDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pattern_get_extend() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pattern_get_filter — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
patternDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pattern_get_filter() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pattern_get_linear_points — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
patternDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pattern_get_linear_points() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pattern_get_matrix — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
patternDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pattern_get_matrix() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pattern_get_radial_circles — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
patternDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pattern_get_radial_circles() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pattern_get_rgba — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
patternDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pattern_get_rgba() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pattern_get_surface — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
patternDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pattern_get_surface() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pattern_get_type — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
patternDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pattern_get_type() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pattern_set_extend — Description
$pattern
, string $extend
) : voidThe function description goes here.
This function is currently not documented; only its argument list is available.
patternDescription...
extendDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pattern_set_extend() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pattern_set_filter — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
patternDescription...
filterDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pattern_set_filter() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pattern_set_matrix — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
patternDescription...
matrixDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pattern_set_matrix() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pattern_status — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
patternDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pattern_status() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pdf_surface_create — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
fileDescription...
widthDescription...
heightDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pdf_surface_create() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_pdf_surface_set_size — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
widthDescription...
heightDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_pdf_surface_set_size() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_ps_get_levels — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_ps_get_levels() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_ps_level_to_string — Description
$level
) : stringThe function description goes here.
This function is currently not documented; only its argument list is available.
levelDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_ps_level_to_string() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_ps_surface_create — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
fileDescription...
widthDescription...
heightDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_ps_surface_create() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_ps_surface_dsc_begin_page_setup — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_ps_surface_dsc_begin_page_setup() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_ps_surface_dsc_begin_setup — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_ps_surface_dsc_begin_setup() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_ps_surface_dsc_comment — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
commentDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_ps_surface_dsc_comment() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_ps_surface_get_eps — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_ps_surface_get_eps() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_ps_surface_restrict_to_level — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
levelDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_ps_surface_restrict_to_level() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_ps_surface_set_eps — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
levelDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_ps_surface_set_eps() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_ps_surface_set_size — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
widthDescription...
heightDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_ps_surface_set_size() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_scaled_font_create — Description
$fontface
, CairoMatrix $matrix
, CairoMatrix $ctm
, CairoFontOptions $fontoptions
) : CairoScaledFontThe function description goes here.
This function is currently not documented; only its argument list is available.
fontfaceDescription...
matrixDescription...
ctmDescription...
fontoptionsDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_scaled_font_create() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_scaled_font_extents — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
scaledfontDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_scaled_font_extents() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_scaled_font_get_ctm — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
scaledfontDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_scaled_font_get_ctm() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_scaled_font_get_font_face — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
scaledfontDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_scaled_font_get_font_face() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_scaled_font_get_font_matrix — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
scaledfontDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_scaled_font_get_font_matrix() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_scaled_font_get_font_options — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
scaledfontDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_scaled_font_get_font_options() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_scaled_font_get_scale_matrix — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
scaledfontDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_scaled_font_get_scale_matrix() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_scaled_font_get_type — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
scaledfontDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_scaled_font_get_type() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_scaled_font_glyph_extents — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
scaledfontDescription...
glyphsDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_scaled_font_glyph_extents() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_scaled_font_status — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
scaledfontDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_scaled_font_status() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_scaled_font_text_extents — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
scaledfontDescription...
textDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_scaled_font_text_extents() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_surface_copy_page — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_surface_copy_page() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_surface_create_similar — Description
$surface
, int $content
, float $width
, float $height
) : CairoSurfaceThe function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
contentDescription...
widthDescription...
heightDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_surface_create_similar() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_surface_finish — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_surface_finish() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_surface_flush — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_surface_flush() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_surface_get_content — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_surface_get_content() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_surface_get_device_offset — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_surface_get_device_offset() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_surface_get_font_options — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_surface_get_font_options() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_surface_get_type — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_surface_get_type() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_surface_mark_dirty_rectangle — Description
$surface
, float $x
, float $y
, float $width
, float $height
) : voidThe function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
xDescription...
yDescription...
widthDescription...
heightDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_surface_mark_dirty_rectangle() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_surface_mark_dirty — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_surface_mark_dirty() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_surface_set_device_offset — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
xDescription...
yDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_surface_set_device_offset() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_surface_set_fallback_resolution — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
xDescription...
yDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_surface_set_fallback_resolution() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_surface_show_page — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_surface_show_page() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_surface_status — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_surface_status() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_surface_write_to_png — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
streamDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_surface_write_to_png() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_svg_surface_create — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
fileDescription...
widthDescription...
heightDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_svg_surface_create() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_svg_surface_restrict_to_version — Description
The function description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
versionDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_svg_surface_restrict_to_version() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
cairo_svg_version_to_string — Description
$version
) : stringThe function description goes here.
This function is currently not documented; only its argument list is available.
versionDescription...
What is returned on success and failure
When does this function issue E_* level errors, and/or throw exceptions.
Example #1 cairo_svg_version_to_string() example
Any text that describes the purpose of the example, or what goes on in the example should be here.
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
Simple class with some static helper methods.
(PECL cairo >= 0.1.0)
Cairo::availableFonts -- cairo_available_fonts — Retrieves the availables font types
Object oriented style:
Procedural style:
Returns an array with the available font backends
This function has no parameters.
A list-type array with all available font backends.
Example #1 Object oriented style
<?php
/* Object Oriented Style */
var_dump(Cairo::availableFonts());
?>
The above example will output something similar to:
array(2) {
[0]=>
string(5) "WIN32"
[1]=>
string(4) "USER"
}
Example #2 Procedural style
<?php
/* Procedural style */
var_dump(cairo_available_fonts());
?>
The above example will output something similar to:
array(2) {
[0]=>
string(5) "WIN32"
[1]=>
string(4) "USER"
}
(PECL cairo >= 0.1.0)
Cairo::availableSurfaces -- cairo_available_surfaces — Retrieves all available surfaces
Object oriented style (method):
Procedural style:
Returns an array with the available surface backends
This function has no parameters.
A list-type array with all available surface backends.
Example #1 Object oriented style
<?php
/* Object Oriented style */
var_dump(Cairo::availableSurfaces());
?>
The above example will output something similar to:
array(6) {
[0]=>
string(5) "IMAGE"
[1]=>
string(3) "PNG"
[2]=>
string(3) "PDF"
[3]=>
string(2) "PS"
[4]=>
string(3) "SVG"
[5]=>
string(5) "WIN32"
}
Example #2 Procedural style
<?php
/* Procedural style */
var_dump(cairo_available_surfaces());
?>
The above example will output something similar to:
array(6) {
[0]=>
string(5) "IMAGE"
[1]=>
string(3) "PNG"
[2]=>
string(3) "PDF"
[3]=>
string(2) "PS"
[4]=>
string(3) "SVG"
[5]=>
string(5) "WIN32"
}
(PECL cairo >= 0.1.0)
Cairo::statusToString -- cairo_status_to_string — Retrieves the current status as string
Object oriented style (method):
$status
) : stringProcedural style:
$status
) : stringRetrieves the current status as a readable string
A string containing the current status of a CairoContext object
Example #1 Object oriented style
<?php
$surface = new CairoImageSurface(CairoFormat::ARGB32, 50, 50);
$context = new CairoContext($surface);
var_dump(Cairo::statusToString($context->status()));
?>
The above example will output something similar to:
string(7) "success"
Example #2 Procedural style
<?php
$surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 50, 50);
$context = cairo_create($surface);
var_dump(cairo_status_to_string(cairo_status($context)));
?>
The above example will output something similar to:
string(7) "success"
(PECL cairo >= 0.1.0)
Cairo::version -- cairo_version — Retrieves cairo's library version
Object oriented style (method):
Procedural style:
Retrieves the current version of the cairo library as an integer value
This function has no parameters.
Current Cairo library version integer
Example #1 Object oriented style
<?php
var_dump(Cairo::version());
?>
The above example will output something similar to:
int(10808)
Example #2 Procedural style
<?php
var_dump(cairo_version());
?>
The above example will output something similar to:
int(10808)
(PECL cairo >= 0.1.0)
Cairo::versionString -- cairo_version_string — Retrieves cairo version as string
Object oriented style (method):
Procedural style:
Retrieves the current cairo library version as a string.
This function has no parameters.
Current Cairo library version string
Example #1 Object oriented style
<?php
var_dump(Cairo::versionString());
?>
The above example will output something similar to:
string(5) "1.8.8"
Example #2 Procedural style
<?php
var_dump(cairo_version_string());
?>
The above example will output something similar to:
string(5) "1.8.8"
(PECL cairo >= 0.1.0)
Context is the main object used when drawing with cairo. To draw with cairo, you create a CairoContext, set the target CairoSurface, and drawing options for the CairoContext, create shapes with functions . like CairoContext::moveTo() and CairoContext::lineTo(), and then draw shapes with CairoContext::stroke() or CairoContext::fill(). Contexts can be pushed to a stack via CairoContext::save(). They may then safely be changed, without losing the current state. Use CairoContext::restore() to restore to the saved state.
(PECL cairo >= 0.1.0)
CairoContext::appendPath -- cairo_append_path — Appends a path to current path
Object oriented style (method):
Procedural style:
Appends the path onto the current path.
The path may be either the return value from one of CairoContext::copyPath() or
CairoContext::copyPathFlat();
if path is not a valid CairoPath instance
a CairoException will be thrown
contextCairoContext object
pathCairoPath object
No value is returned.
Example #1 Object oriented style
<?php
$surface = new CairoImageSurface(CairoFormat::ARGB32, 50, 50);
$context = new CairoContext($surface);
$path = $context->copyPath();
$context->appendPath($path);
?>
Example #2 Procedural style
<?php
$surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 50, 50);
$context = cairo_create($surface);
$path = cairo_copy_path($context);
cairo_append_path($context, $path);
?>
(PECL cairo >= 0.1.0)
CairoContext::arc -- cairo_arc — Adds a circular arc
Object oriented style (method):
$x
, float $y
, float $radius
, float $angle1
, float $angle2
) : voidProcedural style:
$context
, float $x
, float $y
, float $radius
, float $angle1
, float $angle2
) : void
Adds a circular arc of the given radius to the current path.
The arc is centered at (x, y), begins at
angle1 and proceeds in the direction of increasing angles to end at
angle2.
If angle2 is less than angle1 it will be
progressively increased by 2*M_PI until it is greater than angle1.
If there is a current point, an initial line segment will be added to the path to connect the
current point to the beginning of the arc. If this initial line is undesired,
it can be avoided by calling CairoContext::newSubPath() or procedural
cairo_new_sub_path() before calling CairoContext::arc()
or cairo_arc().
Angles are measured in radians. An angle of 0.0 is in the direction of the positive X axis
(in user space). An angle of M_PI/2.0 radians (90 degrees) is in the direction of the positive
Y axis (in user space). Angles increase in the direction from the positive X axis toward the
positive Y axis. So with the default transformation matrix, angles increase in a clockwise direction.
(To convert from degrees to radians, use degrees * (M_PI / 180.).)
This function gives the arc in the direction of increasing angles; see
CairoContext::arcNegative() or cairo_arc_negative()
to get the arc in the direction of decreasing angles.
contextA valid CairoContext object
xx position
yy position
radiusRadius of the arc
angle1start angle
angle2end angle
No value is returned.
Example #1 Object oriented style
<?php
$s = new CairoImageSurface(CairoFormat::ARGB32, 100, 100);
$c = new CairoContext($s);
$c->setSourceRgb(0, 0, 0);
$c->paint();
$c->setLineWidth(1);
$c->setSourceRgb(1, 1, 1);
for ($r = 50; $r > 0; $r -= 10) {
$c->arc(50, 50, $r, 0, 2 * M_PI);
$c->stroke();
$c->fill();
}
$s->writeToPng(dirname(__FILE__) . '/CairoContext__arc.png');
?>
Example #2 Procedural style
<?php
$s = cairo_image_surface_create(CAIRO_SURFACE_TYPE_IMAGE, 100, 100);
$c = cairo_create($s);
cairo_set_source_rgb($c, 0, 0, 0);
cairo_paint($c);
cairo_set_source_rgb($c, 1, 1, 1);
cairo_set_line_width($c, 1);
for ($r = 50; $r > 0; $r -= 10) {
cairo_arc($c, 50, 50, $r, 0, 2 * M_PI);
cairo_stroke($c);
cairo_fill($c);
}
cairo_surface_write_to_png($s, dirname(__FILE__) . '/cairo_arc.png');
?>
(PECL cairo >= 0.1.0)
CairoContext::arcNegative -- cairo_arc_negative — Adds a negative arc
Object oriented style (method):
$x
, float $y
, float $radius
, float $angle1
, float $angle2
) : voidProcedural style:
$context
, float $x
, float $y
, float $radius
, float $angle1
, float $angle2
) : void
Adds a circular arc of the given radius to the current path.
The arc is centered at (x, y), begins at
angle1 and proceeds in the direction of decreasing angles to end at
angle2. If angle2 is greater than
angle1 it will be progressively decreased by 2*M_PI until it is less than
angle1.
See CairoContext::arc() or cairo_arc() for more details.
This function differs only in the direction of the arc between the two angles.
contextA valid CairoContext object
xdouble x position
ydouble y position
radiusThe radius of the desired negative arc
angle1Start angle of the arc
angle2End angle of the arc
No value is returned.
Example #1 Object oriented style
<?php
$s = new CairoImageSurface(CairoFormat::ARGB32, 100, 100);
$c = new CairoContext($s);
$c->setSourceRgb(0, 0, 0);
$c->paint();
$c->setLineWidth(1);
$c->setSourceRgb(1, 1, 1);
for ($r = 50; $r > 0; $r -= 10) {
$c->arcNegative(50, 50, $r, 2 * M_PI, 0);
$c->stroke();
$c->fill();
}
$s->writeToPng(dirname(__FILE__) . '/CairoContext__arcNegative.png');
?>
Example #2 Procedural style
<?php
$s = cairo_image_surface_create(CAIRO_SURFACE_TYPE_IMAGE, 100, 100);
$c = cairo_create($s);
cairo_set_source_rgb($c, 0, 0, 0);
cairo_paint($c);
cairo_set_source_rgb($c, 1, 1, 1);
cairo_set_line_width($c, 1);
for ($r = 50; $r > 0; $r -= 10) {
cairo_arc_negative($c, 50, 50, $r, 2 * M_PI, 0);
cairo_stroke($c);
cairo_fill($c);
}
cairo_surface_write_to_png($s, dirname(__FILE__) . '/cairo_arc_negative.png');
?>
(PECL cairo >= 0.1.0)
CairoContext::clip -- cairo_clip — Establishes a new clip region
Object oriented style (method):
Procedural style:
Establishes a new clip region by intersecting the current clip region with the current path as it would be filled by CairoContext::fill() or cairo_fill() and according to the current fill rule (see CairoContext::setFillRule() or cairo_set_fill_rule()).
After CairoContext::clip() or cairo_clip(), the current path will be cleared from the cairo context.
The current clip region affects all drawing operations by effectively masking out any changes to the surface that are outside the current clip region.
Calling CairoContext::clip() or cairo_clip() can only make the clip region smaller, never larger. But the current clip is part of the graphics state, so a temporary restriction of the clip region can be achieved by calling CairoContext::clip() or cairo_clip() within a CairoContext::save()/CairoContext::restore() or cairo_save()/cairo_restore() pair. The only other means of increasing the size of the clip region is CairoContext::resetClip() or procedural cairo_reset_clip().
contextA valid CairoContext object
No value is returned.
Example #1 Object oriented style
<?php
$surface = new CairoImageSurface(CairoFormat::ARGB32, 50, 50);
$context = new CairoContext($surface);
$context->clip();
?>
Example #2 Procedural style
<?php
$surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 50, 50);
$context = cairo_create($surface);
cairo_clip($context);
?>
(PECL cairo >= 0.1.0)
CairoContext::clipExtents -- cairo_clip_extents — Computes the area inside the current clip
Object oriented style (method):
Procedural style:
Computes a bounding box in user coordinates covering the area inside the current clip.
contextA valid CairoContext object
An array containing the (float)x1, (float)y1, (float)x2, (float)y2, coordinates covering the area inside the current clip
Example #1 Object oriented style
<?php
$surface = new CairoImageSurface(CairoFormat::ARGB32, 50, 50);
$context = new CairoContext($surface);
var_dump($context->clipExtents());
?>
The above example will output something similar to:
array(4) {
[0]=>
float(0)
[1]=>
float(0)
[2]=>
float(50)
[3]=>
float(50)
}
Example #2 Procedural style
<?php
$surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 50, 50);
$context = cairo_create($surface);
var_dump(cairo_clip_extents($context));
?>
The above example will output something similar to:
array(4) {
[0]=>
float(0)
[1]=>
float(0)
[2]=>
float(50)
[3]=>
float(50)
}
(PECL cairo >= 0.1.0)
CairoContext::clipPreserve -- cairo_clip_preserve — Establishes a new clip region from the current clip
Object oriented style (method):
Procedural style:
Establishes a new clip region by intersecting the current clip region with the current path as it would be filled by Context.fill() and according to the current FILL RULE (see CairoContext::setFillRule() or cairo_set_fill_rule()).
Unlike CairoContext::clip(), CairoContext::clipPreserve() preserves the path within the Context. The current clip region affects all drawing operations by effectively masking out any changes to the surface that are outside the current clip region.
Calling CairoContext::clipPreserve() can only make the clip region smaller, never larger. But the current clip is part of the graphics state, so a temporary restriction of the clip region can be achieved by calling CairoContext::clipPreserve() within a CairoContext::save()/CairoContext::restore() pair. The only other means of increasing the size of the clip region is CairoContext::resetClip().
contextA valid CairoContext object
No value is returned.
Example #1 Object oriented style
<?php
$surface = new CairoImageSurface(CairoFormat::ARGB32, 50, 50);
$context = new CairoContext($surface);
$context->clipPreserve();
?>
Example #2 Procedural style
<?php
$surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 50, 50);
$context = cairo_create($surface);
cairo_clip_preserve($context);
?>
(PECL cairo >= 0.1.0)
CairoContext::clipRectangleList -- cairo_clip_rectangle_list — Retrieves the current clip as a list of rectangles
Object oriented style (method):
Procedural style:
Returns a list-type array with the current clip region as a list of rectangles in user coordinates
contextA valid CairoContext object created with CairoContext::__construct() or cairo_create()
An array of user-space represented rectangles for the current clip
(The status in the list may be CAIRO_STATUS_CLIP_NOT_REPRESENTABLE to indicate that the clip region cannot be represented as a list of user-space rectangles. The status may have other values to indicate other errors.)
Example #1 Object oriented style
<?php
$surface = new CairoImageSurface(CairoFormat::ARGB32, 50, 50);
$context = new CairoContext($surface);
var_dump($context->clipRectangleList());
?>
The above example will output something similar to:
array(1) {
[0]=>
array(4) {
["x"]=>
float(0)
["y"]=>
float(0)
["width"]=>
float(50)
["height"]=>
float(50)
}
}
Example #2 Procedural style
<?php
$surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 50, 50);
$context = cairo_create($surface);
var_dump(cairo_clip_rectangle_list($context));
?>
The above example will output something similar to:
array(1) {
[0]=>
array(4) {
["x"]=>
float(0)
["y"]=>
float(0)
["width"]=>
float(50)
["height"]=>
float(50)
}
}
(PECL cairo >= 0.1.0)
CairoContext::closePath -- cairo_close_path — Closes the current path
Object oriented style (method):
Procedural style:
Adds a line segment to the path from the current point to the beginning of the current sub-path, (the most recent point passed to CairoContext::moveTo()), and closes this sub-path. After this call the current point will be at the joined endpoint of the sub-path.
The behavior of close_path() is distinct from simply calling CairoContext::lineTo() with the equivalent coordinate in the case of stroking. When a closed sub-path is stroked, there are no caps on the ends of the sub-path. Instead, there is a line join connecting the final and initial segments of the sub-path.
If there is no current point before the call to CairoContext::closePath(), this function will have no effect.
contextA valid CairoContext object created with CairoContext::__construct() or cairo_create()
No value is returned.
Example #1 Object oriented style
<?php
$surface = new CairoImageSurface(CairoFormat::ARGB32, 50, 50);
$context = new CairoContext($surface);
$context->closePath();
?>
Example #2 Procedural style
<?php
$surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 50, 50);
$context = cairo_create($surface);
cairo_close_path($context);
?>
(PECL cairo >= 0.1.0)
CairoContext::__construct — Creates a new CairoContext
Creates a new CairoContext object to draw
Example #1 CairoContext::__construct() example
<?php
// The surface to work on
$surface = new CairoImageSurface(CairoFormat::ARGB32, 50, 50);
// Create a new CairoContext for the CairoSurface
$context = new CairoContext($surface);
?>
(PECL cairo >= 0.1.0)
CairoContext::copyPage -- cairo_copy_page — Emits the current page
Object oriented style (method):
Procedural style:
Emits the current page for backends that support multiple pages, but doesn’t clear it, so, the contents of the current page will be retained for the next page too. Use CairoContext::showPage() if you want to get an empty page after the emission.
This is a convenience function that simply calls CairoSurface::copyPage() on CairoContext’s target.
contextA valid CairoContext object created with CairoContext::__construct() or cairo_create()
No value is returned.
Example #1 Object oriented style
<?php
$surface = new CairoImageSurface(CairoFormat::ARGB32, 50, 50);
$context = new CairoContext($surface);
$context->copyPage();
?>
Example #2 Procedural style
<?php
$surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 50, 50);
$context = cairo_create($surface);
cairo_copy_page($context);
?>
(PECL cairo >= 0.1.0)
CairoContext::copyPath -- cairo_copy_path — Creates a copy of the current path
Object oriented style (method):
Procedural style:
Creates a copy of the current path and returns it to the user as a CairoPath. See CairoPath for hints on how to iterate over the returned data structure.
This function will always return a valid CairoPath object, but the result will have no data, if either of the following conditions hold:
context is already in an error state.
In this case CairoPath->status will contain the same status that would be returned by
cairo_status().
contextA valid CairoContext object created with CairoContext::__construct() or cairo_create()
A copy of the current CairoPath in the context
Example #1 Object oriented style
<?php
$surface = new CairoImageSurface(CairoFormat::ARGB32, 50, 50);
$context = new CairoContext($surface);
var_dump($context->copyPath())
?>
The above example will output something similar to:
object(CairoPath)#3 (0) {
}
Example #2 Procedural style
<?php
$surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 50, 50);
$context = cairo_create($surface);
var_dump(cairo_copy_path($context));
?>
The above example will output something similar to:
object(CairoPath)#3 (0) {
}
(PECL cairo >= 0.1.0)
CairoContext::copyPathFlat -- cairo_copy_path_flat — Gets a flattened copy of the current path
Object oriented style (method):
Procedural style:
Gets a flattened copy of the current path and returns it to the user as a CairoPath.
This function is like CairoContext::copyPath() except that any curves in the path will be approximated with piecewise-linear approximations, (accurate to within the current tolerance value). That is, the result is guaranteed to not have any elements of type CAIRO_PATH_CURVE_TO which will instead be replaced by a series of CAIRO_PATH_LINE_TO elements.
contextA CairoContext object
A copy of the current path
Example #1 Object oriented style
<?php
$surface = new CairoImageSurface(CairoFormat::ARGB32, 50, 50);
$context = new CairoContext($surface);
var_dump($context->copyPathFlat());
?>
The above example will output something similar to:
object(CairoPath)#3 (0) {
}
Example #2 Procedural style
<?php
$surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 50, 50);
$context = cairo_create($surface);
var_dump(cairo_copy_path_flat($context));
?>
The above example will output something similar to:
object(CairoPath)#3 (0) {
}
(PECL cairo >= 0.1.0)
CairoContext::curveTo -- cairo_curve_to — Adds a curve
Object oriented style (method):
$x1
, float $y1
, float $x2
, float $y2
, float $x3
, float $y3
) : voidProcedural style:
$context
, float $x1
, float $y1
, float $x2
, float $y2
, float $x3
, float $y3
) : void
Adds a cubic Bezier spline to the path from the current point to position x3
,y3 in user-space coordinates, using x1,
y1 and x2, y2 as the control
points. After this call the current point will be x3, y3.
If there is no current point before the call to CairoContext::curveTo()
this function will behave as if preceded by a call to CairoContext::moveTo()
(x1, y1).
contextA valid CairoContext object created with CairoContext::__construct() or cairo_create()
x1First control point in the x axis for the curve
y1First control point in the y axis for the curve
x2Second control point in x axis for the curve
y2Second control point in y axis for the curve
x3Final point in the x axis for the curve
y3Final point in the y axis for the curve
No value is returned.
Example #1 Object oriented style
<?php
$s = new CairoImageSurface(CairoFormat::ARGB32, 100, 100);
$c = new CairoContext($s);
$c->setSourceRgb(0, 0, 0);
$c->paint();
$c->moveTo(10, 50);
$c->setLineWidth(5);
$c->setSourceRgb(.1, 0, 1);
$c->curveTo(20, 80, 80, 20, 90, 50);
$c->stroke();
$s->writeToPng(dirname(__FILE__) . '/curveTo.png');
?>
Example #2 Procedural style
<?php
$s = cairo_image_surface_create(CAIRO_SURFACE_TYPE_IMAGE, 100, 100);
$c = cairo_create($s);
cairo_set_source_rgb($c, 0, 0, 0);
cairo_paint($c);
cairo_move_to($c, 10, 50);
cairo_set_line_width($c, 5);
cairo_set_source_rgb($c, .1, 0, 1);
cairo_curve_to($c, 20, 80, 80, 20, 90, 50);
cairo_stroke($c);
cairo_surface_write_to_png($s, dirname(__FILE__) . '/curve_to.png');
?>
(PECL cairo >= 0.1.0)
CairoContext::deviceToUser -- cairo_device_to_user — Transform a coordinate
Object oriented style (method):
$x
, float $y
) : arrayProcedural style:
Transform a coordinate from device space to user space by multiplying the given point by the inverse of the current transformation matrix (CTM).
contextA valid CairoContext object created with CairoContext::__construct() or cairo_create()
xx value of the coordinate
yy value of the coordinate
An array containing the x and y coordinates in the user-space
(PECL cairo >= 0.1.0)
CairoContext::deviceToUserDistance -- cairo_device_to_user_distance — Transform a distance
Object oriented style (method):
$x
, float $y
) : arrayProcedural style:
Transform a distance vector from device space to user space. This function is similar to
CairoContext::deviceToUser() or cairo_device_to_user()
except that the translation components of the inverse Cairo Transformation Matrix will be
ignored when transforming (x,y).
contextA valid CairoContext object created with CairoContext::__construct() or cairo_create()
xX component of a distance vector
yY component of a distance vector
Returns an array with the x and y values of a distance vector in the user-space
(PECL cairo >= 0.1.0)
CairoContext::fill -- cairo_fill — Fills the current path
Object oriented style (method):
Procedural style:
A drawing operator that fills the current path according to the current CairoFillRule, (each sub-path is implicitly closed before being filled). After CairoContext::fill() or cairo_fill(), the current path will be cleared from the CairoContext.
contextA valid CairoContext object created with CairoContext::__construct() or cairo_create()
No value is returned.
Example #1 Object oriented style
<?php
$s = new CairoImageSurface(CairoFormat::ARGB32, 100, 100);
$c = new CairoContext($s);
$c->setSourceRgb(0, 0, 0);
$c->paint();
$c->setSourceRgb(1, 1, 1);
$c->rectangle(0, 0, 50, 50);
$c->fill();
$c->setSourceRgb(0, 1, 0);
$c->rectangle(50, 50, 50, 50);
$c->fill();
$s->writeToPng(dirname(__FILE__) . '/CairoContext_fill.png');
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
$s = cairo_image_surface_create(CAIRO_SURFACE_TYPE_IMAGE, 100, 100);
$c = cairo_create($s);
cairo_set_source_rgb($c, 0, 0, 0);
cairo_paint($c);
cairo_set_source_rgb($c, 1, 1, 1);
cairo_rectangle($c, 0, 0, 50, 50);
cairo_fill($c);
cairo_set_source_rgb($c, 0, 1, 0);
cairo_rectangle($c, 50, 50, 50, 50);
cairo_fill($c);
cairo_surface_write_to_png($s, dirname(__FILE__) . '/cairo_fill.png');
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::fillExtents -- cairo_fill_extents — Computes the filled area
Object oriented style (method):
Procedural style:
Computes a bounding box in user coordinates covering the area that would be affected, (the “inked” area), by a CairoContext::fill() operation given the current path and fill parameters. If the current path is empty, returns an empty rectangle (0,0,0,0). Surface dimensions and clipping are not taken into account.
Contrast with CairoContext::pathExtents(), which is similar, but returns non-zero extents for some paths with no inked area, (such as a simple line segment).
Note that CairoContext::fillExtents() must necessarily do more work to compute the precise inked areas in light of the fill rule, so CairoContext::pathExtents() may be more desirable for sake of performance if the non-inked path extents are desired.
contextA valid CairoContext object created with CairoContext::__construct() or cairo_create()
An array with the coordinates of the afected area
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::fillPreserve -- cairo_fill_preserve — Fills and preserve the current path
Object oriented style (method):
Procedural style:
A drawing operator that fills the current path according to the current CairoFillRule, (each sub-path is implicitly closed before being filled). Unlike CairoContext::fill(), CairoContext::fillPreserve() (Procedural cairo_fill(), cairo_fill_preserve(), respectively) preserves the path within the Context.
contextA valid CairoContext object created with CairoContext::__construct() or cairo_create()
No value is returned.
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::fontExtents -- cairo_font_extents — Get the font extents
Object oriented style (method):
Procedural style:
Gets the font extents for the currently selected font.
contextDescription...
An array containing the font extents for the current font.
Example #1 Object oriented style
<?php
$sur = new CairoImageSurface(CairoFormat::ARGB32, 50, 50);
$con = new CairoContext($sur);
var_dump($con->fontExtents());
?>
The above example will output something similar to:
array(5) {
["ascent"]=>
float(10)
["descent"]=>
float(3)
["height"]=>
float(13.3125)
["max_x_advance"]=>
float(26.65625)
["max_y_advance"]=>
float(0)
}
Example #2 Procedural style
<?php
$sur = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 50, 50);
$con = cairo_create($sur);
var_dump(cairo_font_extents($con));
?>
The above example will output something similar to:
array(5) {
["ascent"]=>
float(10)
["descent"]=>
float(3)
["height"]=>
float(13.3125)
["max_x_advance"]=>
float(26.65625)
["max_y_advance"]=>
float(0)
}
(PECL cairo >= 0.1.0)
CairoContext::getAntialias -- cairo_get_antialias — Retrieves the current antialias mode
Object oriented style (method):
Procedural style:
Returns the current CairoAntialias mode, as set by CairoContext::setAntialias().
contextA valid CairoContext object created with CairoContext::__construct() or cairo_create()
The current CairoAntialias mode.
Example #1 Object oriented style
<?php
$surface = new CairoImageSurface(CairoFormat::ARGB32, 50, 50);
$context = new CairoContext($surface);
$context->setAntialias(CairoAntialias::MODE_SUBPIXEL);
var_dump($context->getAntialias());
?>
The above example will output something similar to:
int(3)
Example #2 Procedural style
<?php
$sur = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 50, 50);
$con = cairo_create($sur);
cairo_set_antialias($con, CAIRO_ANTIALIAS_SUBPIXEL);
var_dump(cairo_get_antialias($con));
?>
The above example will output something similar to:
int(3)
(PECL cairo >= 0.1.0)
CairoContext::getCurrentPoint -- cairo_get_current_point — The getCurrentPoint purpose
Object oriented style
Procedural style
Gets the current point of the current path, which is conceptually the final point reached by the path so far.
The current point is returned in the user-space coordinate system. If there is no defined current point or if cr is in an error status, x and y will both be set to 0.0. It is possible to check this in advance with CairoContext::hasCurrentPoint().
Most path construction functions alter the current point. See the following for details on how they affect the current point: CairoContext::newPath(), CairoContext::newSubPath(), CairoContext::appendPath(), CairoContext::closePath(), CairoContext::moveTo(), CairoContext::lineTo(), CairoContext::curveTo(), CairoContext::relMoveTo(), CairoContext::relLineTo(), CairoContext::relCurveTo(), CairoContext::arc(), CairoContext::arcNegative(), CairoContext::rectangle(), CairoContext::textPath(), CairoContext::glyphPath().
Some functions use and alter the current point but do not otherwise change current path: CairoContext::showText().
Some functions unset the current path and as a result, current point: CairoContext::fill(), CairoContext::stroke().
An array containing the x (index 0) and y (index 1) coordinates of the current point.
Example #1 Object oriented style
<?php
$s = new CairoImageSurface(CairoFormat::ARGB32, 100, 100);
$c = new CairoContext($s);
$c->moveTo(10, 10);
var_dump($c->getCurrentPoint());
?>
The above example will output something similar to:
array(2) {
[0]=>
float(10)
[1]=>
float(10)
}
Example #2 Procedural style
<?php
$s = cairo_image_surface_create(CAIRO_SURFACE_TYPE_IMAGE, 100, 100);
$c = cairo_create($s);
cairo_move_to($c, 10, 10);
var_dump(cairo_get_current_point($c));
?>
The above example will output something similar to:
array(2) {
[0]=>
float(10)
[1]=>
float(10)
}
(PECL cairo >= 0.1.0)
CairoContext::getDash -- cairo_get_dash — The getDash purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::getDashCount -- cairo_get_dash_count — The getDashCount purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::getFillRule -- cairo_get_fill_rule — The getFillRule purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::getFontFace -- cairo_get_font_face — The getFontFace purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::getFontMatrix -- cairo_get_font_matrix — The getFontMatrix purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::getFontOptions -- cairo_get_font_options — The getFontOptions purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::getGroupTarget -- cairo_get_group_target — The getGroupTarget purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::getLineCap -- cairo_get_line_cap — The getLineCap purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::getLineJoin -- cairo_get_line_join — The getLineJoin purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::getLineWidth -- cairo_get_line_width — The getLineWidth purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::getMatrix -- cairo_get_matrix — The getMatrix purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::getMiterLimit -- cairo_get_miter_limit — The getMiterLimit purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::getOperator -- cairo_get_operator — The getOperator purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::getScaledFont -- cairo_get_scaled_font — The getScaledFont purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::getSource -- cairo_get_source — The getSource purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::getTarget -- cairo_get_target — The getTarget purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::getTolerance -- cairo_get_tolerance — The getTolerance purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::glyphPath -- cairo_glyph_path — The glyphPath purpose
Object oriented style
$glyphs
) : voidProcedural style
Adds closed paths for the glyphs to the current path. The generated path if filled, achieves an effect similar to that of CairoContext::showGlyphs().
No value is returned.
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::hasCurrentPoint -- cairo_has_current_point — The hasCurrentPoint purpose
Object oriented style (method):
Procedural style:
Returns whether a current point is defined on the current path. See CairoContext::getCurrentPoint() for details on the current point.
Whether a current point is defined
Example #1 Object oriented style
<?php
$s = new CairoImageSurface(CairoFormat::ARGB32, 100, 100);
$c = new CairoContext($s);
var_dump($c->hasCurrentPoint());
$c->moveTo(10, 10);
var_dump($c->hasCurrentPoint());
?>
The above example will output:
bool(false) bool(true)
Example #2 Procedural style
<?php
$s = cairo_image_surface_create(CAIRO_SURFACE_TYPE_IMAGE, 100, 100);
$c = cairo_create($s);
var_dump(cairo_has_current_point($c));
cairo_move_to($c, 10, 10);
var_dump(cairo_has_current_point($c));
?>
The above example will output:
bool(false) bool(true)
(PECL cairo >= 0.1.0)
CairoContext::identityMatrix -- cairo_identity_matrix — The identityMatrix purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::inFill -- cairo_in_fill — The inFill purpose
Object oriented style (method):
$x
, float $y
) : boolProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
xDescription...
yDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::inStroke -- cairo_in_stroke — The inStroke purpose
Object oriented style (method):
$x
, float $y
) : boolProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
xDescription...
yDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::lineTo -- cairo_line_to — The lineTo purpose
Object oriented style (method):
$x
, float $y
) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
xDescription...
yDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::mask -- cairo_mask — The mask purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
patternDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::maskSurface -- cairo_mask_surface — The maskSurface purpose
Object oriented style (method):
Procedural style:
$context
, CairoSurface $surface
[, float $x
[, float $y
]] ) : voidDescription here.
This function is currently not documented; only its argument list is available.
contextDescription...
surfaceDescription...
xDescription...
yDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::moveTo -- cairo_move_to — The moveTo purpose
Object oriented style (method):
$x
, float $y
) : voidProcedural style:
Begin a new sub-path. After this call the current point will be (x, y).
contextA valid CairoContext object.
xThe x coordinate of the new position.
yThe y coordinate of the new position
No value is returned.
Example #1 Object oriented style
<?php
$s = new CairoImageSurface(CairoFormat::ARGB32, 100, 100);
$c = new CairoContext($s);
$c->setSourceRgb(0, 0, 0);
$c->paint();
// Move 10 pixels across, and 10 pixels down
$c->moveTo(10, 10);
$c->lineTo(90, 90);
$c->setLineWidth(2);
$c->setSourceRgb(1, 1, 1);
$c->stroke();
// Move 90 pixels across, and 10 pixels down
$c->moveTo(90, 10);
$c->lineTo(10, 90);
$c->setLineWidth(2);
$c->setSourceRgb(1, 1, 1);
$c->stroke();
$s->writeToPng(dirname(__FILE__) . '/CairoContext_moveTo.png');
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
$s = cairo_image_surface_create(CAIRO_SURFACE_TYPE_IMAGE, 100, 100);
$c = cairo_create($s);
cairo_set_source_rgb($c, 0, 0, 0);
cairo_paint($c);
// Move 10 pixels across, and 10 pixels down
cairo_move_to($c, 10, 10);
cairo_line_to($c, 90, 90);
cairo_set_line_width($c, 2);
cairo_set_source_rgb($c, 1, 1, 1);
cairo_stroke($c);
// Move 90 pixels across, and 10 pixels down
cairo_move_to($c, 90, 10);
cairo_line_to($c, 10, 90);
cairo_set_line_width($c, 2);
cairo_set_source_rgb($c, 1, 1, 1);
cairo_stroke($c);
cairo_surface_write_to_png($s, dirname(__FILE__) . '/cairo_move_to.png');
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::newPath -- cairo_new_path — The newPath purpose
Object oriented style (method):
Procedural style:
Clears the current path. After this call there will be no path and no current point.
contextA valid CairoContext object.
No value is returned.
Example #1 Object oriented style
<?php
// [...]
CairoContext::newPath();
?>
Example #2 Procedural style
<?php
// [...]
cairo_new_path($context);
?>
(PECL cairo >= 0.1.0)
CairoContext::newSubPath -- cairo_new_sub_path — The newSubPath purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::paint -- cairo_paint — The paint purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::paintWithAlpha -- cairo_paint_with_alpha — The paintWithAlpha purpose
Object oriented style (method):
$alpha
) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
alphaDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::pathExtents -- cairo_path_extents — The pathExtents purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::popGroup -- cairo_pop_group — The popGroup purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::popGroupToSource -- cairo_pop_group_to_source — The popGroupToSource purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::pushGroup -- cairo_push_group — The pushGroup purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::pushGroupWithContent -- cairo_push_group_with_content — The pushGroupWithContent purpose
Object oriented style (method):
$content
) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
contentDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::rectangle -- cairo_rectangle — The rectangle purpose
Object oriented style (method):
$x
, float $y
, float $width
, float $height
) : voidProcedural style:
$context
, float $x
, float $y
, float $width
, float $height
) : voidDescription here.
This function is currently not documented; only its argument list is available.
contextDescription...
xDescription...
yDescription...
widthDescription...
heightDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::relCurveTo -- cairo_rel_curve_to — The relCurveTo purpose
Object oriented style (method):
$x1
, float $y1
, float $x2
, float $y2
, float $x3
, float $y3
) : voidProcedural style:
$context
, float $x1
, float $y1
, float $x2
, float $y2
, float $x3
, float $y3
) : voidDescription here.
This function is currently not documented; only its argument list is available.
contextDescription...
x1Description...
y1Description...
x2Description...
y2Description...
x3Description...
y3Description...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::relLineTo -- cairo_rel_line_to — The relLineTo purpose
Object oriented style (method):
$x
, float $y
) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
xDescription...
yDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::relMoveTo -- cairo_rel_move_to — The relMoveTo purpose
Object oriented style (method):
$x
, float $y
) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
xDescription...
yDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::resetClip -- cairo_reset_clip — The resetClip purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::restore -- cairo_restore — The restore purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::rotate -- cairo_rotate — The rotate purpose
Object oriented style (method):
$angle
) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
angleDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::save -- cairo_save — The save purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::scale -- cairo_scale — The scale purpose
Object oriented style (method):
$x
, float $y
) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
xDescription...
yDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::selectFontFace -- cairo_select_font_face — The selectFontFace purpose
Object oriented style (method):
$family
[, int $slant
[, int $weight
]] ) : voidProcedural style:
$context
, string $family
[, int $slant
[, int $weight
]] ) : voidDescription here.
This function is currently not documented; only its argument list is available.
contextDescription...
familyDescription...
slantDescription...
weightDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::setAntialias -- cairo_set_antialias — The setAntialias purpose
Object oriented style (method):
$antialias
] ) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
antialiasDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::setDash -- cairo_set_dash — The setDash purpose
Object oriented style (method):
$dashes
[, float $offset
] ) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
dashesDescription...
offsetDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::setFillRule -- cairo_set_fill_rule — The setFillRule purpose
Object oriented style (method):
$setting
) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
settingDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::setFontFace -- cairo_set_font_face — The setFontFace purpose
Object oriented style (method):
Procedural style:
Sets the font-face for a given context.
contextA CairoContext object to change the font-face for.
fontfaceA CairoFontFace object
No value is returned
Example #1 Object oriented style
<?php
// New surface with white background
$s = new CairoImageSurface(CairoFormat::ARGB32, 300, 100);
$c = new CairoContext($s);
$c->setSourceRgb(1, 1, 1);
$c->paint();
// Draw some text
$c->setSourceRgb(0, 0, 0);
$c->moveTo(10, 60);
// Create a new font face
$f = new CairoToyFontFace("sans-serif", CairoFontSlant::NORMAL, CairoFontWeight::NORMAL);
$c->setFontFace($f);
$c->setFontSize(30);
$c->showText('Hello, World!');
$s->writeToPng(dirname(__FILE__) . '/setFontFace.png');
?>
Example #2 Procedural style
<?php
/* ... */
?>
(PECL cairo >= 0.1.0)
CairoContext::setFontMatrix -- cairo_set_font_matrix — The setFontMatrix purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
matrixDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::setFontOptions -- cairo_set_font_options — The setFontOptions purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
fontoptionsDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::setFontSize -- cairo_set_font_size — The setFontSize purpose
Object oriented style (method):
$size
) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
sizeDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::setLineCap -- cairo_set_line_cap — The setLineCap purpose
Object oriented style (method):
$setting
) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
settingDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::setLineJoin -- cairo_set_line_join — The setLineJoin purpose
Object oriented style (method):
$setting
) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
settingDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::setLineWidth -- cairo_set_line_width — The setLineWidth purpose
Object oriented style (method):
$width
) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
widthDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::setMatrix -- cairo_set_matrix — The setMatrix purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
matrixDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::setMiterLimit -- cairo_set_miter_limit — The setMiterLimit purpose
Object oriented style (method):
$limit
) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
limitDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::setOperator -- cairo_set_operator — The setOperator purpose
Object oriented style (method):
$setting
) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
settingDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::setScaledFont -- cairo_set_scaled_font — The setScaledFont purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
scaledfontDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::setSource -- cairo_set_source — The setSource purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
patternDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::setSourceRGB -- cairo_set_source — The setSourceRGB purpose
Object oriented style (method):
$red
, float $green
, float $blue
) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
redDescription...
greenDescription...
blueDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::setSourceRGBA -- cairo_set_source — The setSourceRGBA purpose
Object oriented style (method):
$red
, float $green
, float $blue
, float $alpha
) : voidProcedural style:
$context
, float $red
, float $green
, float $blue
, float $alpha
) : voidDescription here.
This function is currently not documented; only its argument list is available.
contextDescription...
redDescription...
greenDescription...
blueDescription...
alphaDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::setSourceSurface -- cairo_set_source_surface — The setSourceSurface purpose
Object oriented style (method):
Procedural style:
$context
, CairoSurface $surface
[, float $x
[, float $y
]] ) : voidDescription here.
This function is currently not documented; only its argument list is available.
contextDescription...
surfaceDescription...
xDescription...
yDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::setTolerance -- cairo_set_tolerance — The setTolerance purpose
Object oriented style (method):
$tolerance
) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
toleranceDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::showPage -- cairo_show_page — The showPage purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::showText -- cairo_show_text — The showText purpose
Object oriented style (method):
$text
) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
textDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::status -- cairo_status — The status purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::stroke -- cairo_stroke — The stroke purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::strokeExtents -- cairo_stroke_extents — The strokeExtents purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::strokePreserve -- cairo_stroke_preserve — The strokePreserve purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::textExtents -- cairo_text_extents — The textExtents purpose
Object oriented style (method):
$text
) : arrayProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
textDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::textPath -- cairo_text_path — The textPath purpose
Object oriented style
$string
) : voidProcedural style
Adds closed paths for text to the current path. The generated path, if filled, achieves an effect similar to that of CairoContext::showText().
Text conversion and positioning is done similar to CairoContext::showText().
Like CairoContext::showText(), after this call the current point is moved to the origin of where the next glyph would be placed in this same progression. That is, the current point will be at the origin of the final glyph offset by its advance values. This allows for chaining multiple calls to CairoContext::showText() without having to set current point in between.
Note: The CairoContext::textPath() function call is part of what the cairo designers call the "toy" text API. It is convenient for short demos and simple programs, but it is not expected to be adequate for serious text-using applications. See CairoContext::glyphPath() for the "real" text path API in cairo.
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::transform -- cairo_transform — The transform purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
matrixDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::translate -- cairo_translate — The translate purpose
Object oriented style (method):
$x
, float $y
) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
xDescription...
yDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::userToDevice -- cairo_user_to_device — The userToDevice purpose
Object oriented style (method):
$x
, float $y
) : arrayProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
xDescription...
yDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoContext::userToDeviceDistance -- cairo_user_to_device_distance — The userToDeviceDistance purpose
Object oriented style (method):
$x
, float $y
) : arrayProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
xDescription...
yDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
(No version information available, might only be in Git)
CairoStatus is used to indicate errors that can occur when using Cairo. In some cases it is returned directly by functions. but when using CairoContext, the last error, if any, is stored in the object and can be retrieved with CairoContext::status() or cairo_status(). New entries may be added in future versions.
Use Cairo::statusToString() or cairo_status_to_string() to get a human-readable representation of an error message.
CairoStatus::SUCCESSNo error has occurred
CairoStatus::NO_MEMORYOut of memory
CairoStatus::INVALID_RESTOREcairo_restore() called without matching cairo_save()
CairoStatus::INVALID_POP_GROUPNo saved group to pop
CairoStatus::NO_CURRENT_POINTNo current point defined
CairoStatus::INVALID_MATRIXInvalid matrix (not invertible)
CairoStatus::INVALID_STATUSInvalid value for an input CairoStatus>
CairoStatus::NULL_POINTERNull pointer
CairoStatus::INVALID_STRINGInput string not valid UTF-8 string
CairoStatus::INVALID_PATH_DATAInput path data not valid
CairoStatus::READ_ERRORError while reading from input stream
CairoStatus::WRITE_ERRORError while writing to output stream
CairoStatus::SURFACE_FINISHEDTarget surface has been finished
CairoStatus::SURFACE_TYPE_MISMATCHThe surface type is not appropriate for the operation
CairoStatus::PATTERN_TYPE_MISMATCHThe pattern type is not appropriate for the operation
CairoStatus::INVALID_CONTENTInvalid value for an input CairoContent
CairoStatus::INVALID_FORMATInvalid value for an input CairoFormat
CairoStatus::INVALID_VISUALInvalid value for an input Visual
CairoStatus::FILE_NOT_FOUNDFile not found
CairoStatus::INVALID_DASHInvalid value for a dash setting
CairoStatus::INVALID_DSC_COMMENTInvalid value for a DSC comment
CairoStatus::INVALID_INDEXInvalid index passed to getter
CairoStatus::CLIP_NOT_REPRESENTABLEClip region not representable in desired format
CairoStatus::TEMP_FILE_ERRORError creating or writing to a temporary file
CairoStatus::INVALID_STRIDEInvalid value for CairoStride
(PECL cairo >= 0.1.0)
This is the base-class for all other Surface types. CairoSurface is the abstract type representing all different drawing targets that cairo can render to. The actual drawings are performed using a CairoContext.
(PECL cairo >= 0.1.0)
CairoSurface::__construct — The __construct purpose
CairoSurface is an abstract type and, as such, should not be instantiated in your PHP scripts.
This function has no parameters.
No return value
Note:
If you're using a PHP version before 5.3, you must destroy the CairoContext associated with a CairoSurface after you destroy the CairoSurface. Otherwise, you're left with a Circular-reference memory leak.
(PECL cairo >= 0.1.0)
CairoSurface::copyPage -- cairo_copy_page — The copyPage purpose
Object oriented style (method):
Procedural style:
Emits the current page for backends that support multiple pages, but doesn't clear it, so that the contents of the current page will be retained for the next page. Use CairoSurface::showPage() if you want to get an empty page after the emission.
contextA CairoContext object
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoSurface::createSimilar — The createSimilar purpose
$other
, int $content
, string $width
, string $height
) : voidCreate a new surface that is as compatible as possible with an existing surface. For example the new surface will have the same fallback resolution and font options as other. Generally, the new surface will also use the same backend as other, unless that is not possible for some reason. The type of the returned surface may be examined with CairoSurface::getType(). Initially the surface contents are all 0 (transparent if contents have transparency, black otherwise.)
otherAn existing surface used to select the backend of the new surface
contentThe content for the new surface. See the CairoContent class for possible values.
widthWidth of the new surface, (in device-space units).
heightHeight of the new surface, (in device-space units).
A new CairoSurface
Example #1 CairoSurface::createSimilar() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoSurface::finish — The finish purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoSurface::finish() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoSurface::flush — The flush purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoSurface::flush() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoSurface::getContent — The getContent purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoSurface::getContent() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoSurface::getDeviceOffset — The getDeviceOffset purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoSurface::getDeviceOffset() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoSurface::getFontOptions -- cairo_get_font_options — The getFontOptions purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoSurface::getType — The getType purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoSurface::getType() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoSurface::markDirty — The markDirty purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoSurface::markDirty() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoSurface::markDirtyRectangle — The markDirtyRectangle purpose
$x
, float $y
, float $width
, float $height
) : voidThe method description goes here.
This function is currently not documented; only its argument list is available.
xDescription...
yDescription...
widthDescription...
heightDescription...
Description...
Example #1 CairoSurface::markDirtyRectangle() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoSurface::setDeviceOffset — The setDeviceOffset purpose
$x
, float $y
) : voidThe method description goes here.
This function is currently not documented; only its argument list is available.
xDescription...
yDescription...
Description...
Example #1 CairoSurface::setDeviceOffset() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoSurface::setFallbackResolution — The setFallbackResolution purpose
$x
, float $y
) : voidThe method description goes here.
This function is currently not documented; only its argument list is available.
xDescription...
yDescription...
Description...
Example #1 CairoSurface::setFallbackResolution() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoSurface::showPage -- cairo_show_page — The showPage purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoSurface::status -- cairo_status — The status purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoSurface::writeToPng — The writeToPng purpose
$file
) : voidThe method description goes here.
This function is currently not documented; only its argument list is available.
fileDescription...
Description...
Example #1 CairoSurface::writeToPng() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
Svg specific surface class, uses the SVG (standard vector graphics) surface backend.
$other
, int $content
, string $width
, string $height
) : void$x
, float $y
, float $width
, float $height
) : void(PECL cairo >= 0.1.0)
CairoSvgSurface::__construct — The __construct purpose
$file
, float $width
, float $height
)The method description goes here.
This function is currently not documented; only its argument list is available.
fileDescription...
widthDescription...
heightDescription...
Description...
Example #1 CairoSvgSurface::__construct() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoSvgSurface::getVersions -- cairo_svg_surface_get_versions — Used to retrieve a list of supported SVG versions
Object oriented style (method):
Procedural style:
Returns a numerically indexed array of currently available CairoSvgVersion constants. In order to retrieve the string values for each item, use CairoSvgSurface::versionToString().
This function has no parameters.
Returns a numerically indexed array of integer values.
Example #1 CairoSvgSurface::getVersions() example
<?php
/* Grab our list of versions */
$versions = CairoSvgSurface::getVersions();
var_dump($versions);
/* echo the string name of each version */
foreach($versions as $id) {
echo CairoSvgSurface::versionToString($id), PHP_EOL;
}
?>
The above example will output something similar to:
array(2) {
[0]=>
int(0)
[1]=>
int(1)
}
SVG 1.1
SVG 1.2
Example #2 Procedural style
<?php
/* Grab our list of versions */
$versions = cairo_svg_surface_get_versions();
var_dump($versions);
/* echo the string name of each version */
foreach($versions as $id) {
echo cairo_svg_surface_version_to_string($id), PHP_EOL;
}
?>
The above example will output something similar to:
array(2) {
[0]=>
int(0)
[1]=>
int(1)
}
SVG 1.1
SVG 1.2
(PECL cairo >= 0.1.0)
CairoSvgSurface::restrictToVersion — The restrictToVersion purpose
$version
) : voidThe method description goes here.
This function is currently not documented; only its argument list is available.
versionDescription...
Description...
Example #1 CairoSvgSurface::restrictToVersion() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoSvgSurface::versionToString — The versionToString purpose
$version
) : stringThe method description goes here.
This function is currently not documented; only its argument list is available.
versionDescription...
Description...
Example #1 CairoSvgSurface::versionToString() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoImageSurface provide the ability to render to memory buffers either allocated by cairo or by the calling code. The supported image formats are those defined in CairoFormat.
$other
, int $content
, string $width
, string $height
) : void$x
, float $y
, float $width
, float $height
) : void(PECL cairo >= 0.1.0)
CairoImageSurface::__construct — Creates a new CairoImageSurface
$format
, int $width
, int $height
)
Creates a new CairoImageSuface object of type format
formatCan be any defined in CairoFormat
widthThe width of the image surface
heightThe height of the image surface
A new CairoImageSurface
Example #1 CairoImageSurface::__construct() example
<?php
// Creates a image with ARGB32 format of 50 width and 50 height
$surface = new CairoImageSurface(CairoFormat::ARGB32, 50,50);
?>
(PECL cairo >= 0.1.0)
CairoImageSurface::createForData — The createForData purpose
$data
, int $format
, int $width
, int $height
) : voidThe method description goes here.
This function is currently not documented; only its argument list is available.
dataDescription...
formatDescription...
widthDescription...
heightDescription...
Description...
Example #1 CairoImageSurface::createForData() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoImageSurface::createFromPng — Creates a new CairoImageSurface form a png image file
Creates a new CairoImageSurface form a png image file
This method should be called static
filePath to PNG image file
CairoImageSurface object
Example #1 CairoImageSurface::createFromPng() example
<?php
$surface = CairoImageSurface::createFromPng('/path/to/image/file.png');
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoImageSurface::getData — Gets the image data as string
Returns the image data of this surface or NULL if surface is not an image surface, or if CairoContext::finish(), procedural : cairo_surface_finish(), has been called.
This function has no parameters.
The image data as string
Example #1 CairoImageSurface::getData() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoImageSurface::getFormat — Get the image format
Retrieves the image format, as one of the CairoFormat defined
This function has no parameters.
One of the CairoFormat enums
Example #1 CairoImageSurface::getFormat() example
<?php
$surface = new CairoImageSurface(CairoFormat::ARGB32, 50, 50);
var_dump($surface->getFormat()); // 0
$surface2 = new CairoImageSurface(CairoFormat::A8, 50, 50);
var_dump($surface2->getFormat()); // 2
?>
The above example will output something similar to:
int(0) int(2)
(PECL cairo >= 0.1.0)
CairoImageSurface::getHeight — Retrieves the height of the CairoImageSurface
This methods returns the CairoImageSurface height.
This function has no parameters.
CairoImageSurface object height
Example #1 CairoImageSurface::getHeight() example
<?php
// creates a new image surface
$surface = new CairoImageSurface(CairoFormat::ARGB32, 80, 50);
//gets the height
var_dump($surface->getHeight());
?>
The above example will output something similar to:
int(50)
(PECL cairo >= 0.1.0)
CairoImageSurface::getStride — The getStride purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoImageSurface::getStride() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoImageSurface::getWidth — Retrieves the width of the CairoImageSurface
Gets the width of the CairoImageSurface
This function has no parameters.
Returns the width of the CairoImageSurface object
Example #1 CairoImageSurface::getWidth() example
<?php
// creates a new image surface
$surface = new CairoImageSurface(CairoFormat::ARGB32, 80, 50);
//gets the width
var_dump($surface->getWidth());
?>
The above example will output something similar to:
int(80)
(PECL cairo >= 0.1.0)
$other
, int $content
, string $width
, string $height
) : void$x
, float $y
, float $width
, float $height
) : void(PECL cairo >= 0.1.0)
CairoPdfSurface::__construct — The __construct purpose
$file
, float $width
, float $height
)The method description goes here.
This function is currently not documented; only its argument list is available.
fileDescription...
widthDescription...
heightDescription...
Description...
Example #1 CairoPdfSurface::__construct() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoPdfSurface::setSize — The setSize purpose
$width
, float $height
) : voidThe method description goes here.
This function is currently not documented; only its argument list is available.
widthDescription...
heightDescription...
Description...
Example #1 CairoPdfSurface::setSize() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
$other
, int $content
, string $width
, string $height
) : void$x
, float $y
, float $width
, float $height
) : void(PECL cairo >= 0.1.0)
CairoPsSurface::__construct — The __construct purpose
$file
, float $width
, float $height
)The method description goes here.
This function is currently not documented; only its argument list is available.
fileDescription...
widthDescription...
heightDescription...
Description...
Example #1 CairoPsSurface::__construct() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoPsSurface::dscBeginPageSetup — The dscBeginPageSetup purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoPsSurface::dscBeginPageSetup() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoPsSurface::dscBeginSetup — The dscBeginSetup purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoPsSurface::dscBeginSetup() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoPsSurface::dscComment — The dscComment purpose
$comment
) : voidThe method description goes here.
This function is currently not documented; only its argument list is available.
commentDescription...
Description...
Example #1 CairoPsSurface::dscComment() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoPsSurface::getEps — The getEps purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoPsSurface::getEps() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoPsSurface::getLevels — The getLevels purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoPsSurface::getLevels() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoPsSurface::levelToString — The levelToString purpose
$level
) : stringThe method description goes here.
This function is currently not documented; only its argument list is available.
levelDescription...
Description...
Example #1 CairoPsSurface::levelToString() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoPsSurface::restrictToLevel — The restrictToLevel purpose
$level
) : voidThe method description goes here.
This function is currently not documented; only its argument list is available.
levelDescription...
Description...
Example #1 CairoPsSurface::restrictToLevel() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoPsSurface::setEps — The setEps purpose
$level
) : voidThe method description goes here.
This function is currently not documented; only its argument list is available.
levelDescription...
Description...
Example #1 CairoPsSurface::setEps() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoPsSurface::setSize — The setSize purpose
$width
, float $height
) : voidThe method description goes here.
This function is currently not documented; only its argument list is available.
widthDescription...
heightDescription...
Description...
Example #1 CairoPsSurface::setSize() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(No version information available, might only be in Git)
CairoSurfaceType::IMAGEDescription here...
CairoSurfaceType::PDFDescription here...
CairoSurfaceType::PSDescription here...
CairoSurfaceType::XLIBDescription here...
CairoSurfaceType::XCBDescription here...
CairoSurfaceType::GLITZDescription here...
CairoSurfaceType::QUARTZDescription here...
CairoSurfaceType::WIN32Description here...
CairoSurfaceType::BEOSDescription here...
CairoSurfaceType::DIRECTFBDescription here...
CairoSurfaceType::SVGDescription here...
CairoSurfaceType::OS2Description here...
CairoSurfaceType::WIN32_PRINTINGDescription here...
CairoSurfaceType::QUARTZ_IMAGEDescription here...
(PECL cairo >= 0.1.0)
CairoFontFace abstract class represents a particular font at a particular weight, slant, and other characteristic but no transformation or size.
Note: This class can not be instantiated directly, it is created by CairoContext::getFontFace() or cairo_scaled_font_get_font_face().
(PECL cairo >= 0.1.0)
CairoFontFace::__construct — Creates a new CairoFontFace object
CairoFontFace class represents a particular font at a particular weight, slant, and other characteristic but no transformation or size.
Note: This class can't be instantiated directly it is created by CairoContext::getFontFace() or cairo_scaled_font_get_font_face()
This function has no parameters.
Example #1 CairoFontFace::__construct() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoFontFace::getType -- cairo_font_face_get_type — Retrieves the font face type
Object oriented style (method):
Procedural style:
This function returns the type of the backend used to create a font face. See CairoFontType class constants for available types.
This function has no parameters.
A font type that can be any one defined in CairoFontType
Example #1 CairoFontFace::getType() example
<?php
// Creates the font face
$fontface = new CairoToyFontFace('sans-serif');
// Get the font face type
var_dump($fontface->getType());
?>
The above example will output something similar to:
int(0)
(PECL cairo >= 0.1.0)
CairoFontFace::status -- cairo_font_face_status — Check for CairoFontFace errors
Object oriented style (method):
Procedural style:
Checks whether an error has previously occurred for this font face
fontfaceA valid CairoFontFace object
CAIRO_STATUS_SUCCESS or another error such as CAIRO_STATUS_NO_MEMORY.
Example #1 Object oriented style
<?php
// Creates the font face
$fontface = new CairoToyFontFace('sans-serif');
// Get the font face status
var_dump($fontface->status()); // should be the value of CAIRO_STATUS_SUCCESS
?>
The above example will output something similar to:
int(0)
Example #2 Procedural style
<?php
// Creates the font face
$fontface = new CairoToyFontFace('sans-serif');
// Get the font face status
var_dump(cairo_font_face_status($fontface)); // should be the value of CAIRO_STATUS_SUCCESS
?>
The above example will output something similar to:
int(0)
(PECL cairo >= 0.1.0)
An opaque structure holding all options that are used when rendering fonts.
Individual features of a cairo_font_options_t can be set or accessed using functions named cairo_font_options_set_feature_name and cairo_font_options_get_feature_name, like cairo_font_options_set_antialias() and cairo_font_options_get_antialias().
New features may be added to CairoFontOptions in the future. For this reason CairoFontOptions::copy(), CairoFontOptions::equal(), CairoFontOptions::merge(), CairoFontOptions::hash() (cairo_font_options_copy(), cairo_font_options_equal(), cairo_font_options_merge(), and cairo_font_options_hash() in procedural way) should be used to copy, check for equality, merge, or compute a hash value of CairoFontOptions objects.
(PECL cairo >= 0.1.0)
CairoFontOptions::__construct — The __construct purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoFontOptions::__construct() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoFontOptions::equal — The equal purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
otherDescription...
Description...
Example #1 CairoFontOptions::equal() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoFontOptions::getAntialias -- cairo_get_antialias — The getAntialias purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoFontOptions::getHintMetrics — The getHintMetrics purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoFontOptions::getHintMetrics() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoFontOptions::getHintStyle — The getHintStyle purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoFontOptions::getHintStyle() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoFontOptions::getSubpixelOrder — The getSubpixelOrder purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoFontOptions::getSubpixelOrder() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoFontOptions::hash — The hash purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoFontOptions::hash() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoFontOptions::merge — The merge purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
otherDescription...
Description...
Example #1 CairoFontOptions::merge() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoFontOptions::setAntialias -- cairo_set_antialias — The setAntialias purpose
Object oriented style (method):
$antialias
) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
antialiasDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoFontOptions::setHintMetrics — The setHintMetrics purpose
$hint_metrics
) : voidThe method description goes here.
This function is currently not documented; only its argument list is available.
hint_metricsDescription...
Description...
Example #1 CairoFontOptions::setHintMetrics() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoFontOptions::setHintStyle — The setHintStyle purpose
$hint_style
) : voidThe method description goes here.
This function is currently not documented; only its argument list is available.
hint_styleDescription...
Description...
Example #1 CairoFontOptions::setHintStyle() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoFontOptions::setSubpixelOrder — The setSubpixelOrder purpose
$subpixel_order
) : voidThe method description goes here.
This function is currently not documented; only its argument list is available.
subpixel_orderDescription...
Description...
Example #1 CairoFontOptions::setSubpixelOrder() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoFontOptions::status -- cairo_status — The status purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(No version information available, might only be in Git)
Specifies variants of a font face based on their slant.
CairoFontSlant::NORMALUpright font style
CairoFontSlant::ITALICItalic font style
CairoFontSlant::OBLIQUEOblique font style
(No version information available, might only be in Git)
CairoFontType class is an abstract final class that contains constants used to describe the type of a given CairoFontFace or CairoScaledFont. The font types are also known as "font backends" within cairo.
The type of a CairoFontFace is determined by the how it is created, an example would be the CairoToyFontFace::__construct(). The CairoFontFace type can be queried with CairoFontFace::getType() or cairo_font_face_get_type()
The various CairoFontFace functions can be used with a font face of any type.
The type of a CairoScaledFont is determined by the type of the CairoFontFace passed to CairoScaledFont::__construct() or cairo_scaled_font_create(). The scaled font type can be queried with CairoScaledFont::getType() or cairo_scaled_font_get_type().
CairoFontType::TOYThe font was created using CairoToyFont api
CairoFontType::FTThe font is of type CairoFreeType
CairoFontType::WIN32The font is of type Win32
CairoFontType::QUARTZThe font is of type Quartz
CairoFontType::USERThe font was create using cairo's user font api
(No version information available, might only be in Git)
Specifies variants of a font face based on their weight.
CairoFontWeight::NORMALNormal font weight
CairoFontWeight::BOLDBold font weight
(PECL cairo >= 0.1.0)
$font_face
, CairoMatrix $matrix
, CairoMatrix $ctm
, CairoFontOptions $options
)(PECL cairo >= 0.1.0)
CairoScaledFont::__construct — The __construct purpose
$font_face
, CairoMatrix $matrix
, CairoMatrix $ctm
, CairoFontOptions $options
)The method description goes here.
This function is currently not documented; only its argument list is available.
font_faceDescription...
matrixDescription...
ctmDescription...
optionsDescription...
Description...
Example #1 CairoScaledFont::__construct() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoScaledFont::extents — The extents purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoScaledFont::extents() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoScaledFont::getCtm — The getCtm purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoScaledFont::getCtm() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoScaledFont::getFontFace -- cairo_get_font_face — The getFontFace purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoScaledFont::getFontMatrix -- cairo_get_font_matrix — The getFontMatrix purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoScaledFont::getFontOptions -- cairo_get_font_options — The getFontOptions purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoScaledFont::getScaleMatrix — The getScaleMatrix purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoScaledFont::getScaleMatrix() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoScaledFont::getType — The getType purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoScaledFont::getType() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoScaledFont::glyphExtents — The glyphExtents purpose
$glyphs
) : arrayThe method description goes here.
This function is currently not documented; only its argument list is available.
glyphsDescription...
Description...
Example #1 CairoScaledFont::glyphExtents() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoScaledFont::status -- cairo_status — The status purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoScaledFont::textExtents -- cairo_text_extents — The textExtents purpose
Object oriented style (method):
$text
) : arrayProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
textDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
The CairoToyFontFace class can be used instead of CairoContext::selectFontFace() to create a toy font independently of a context.
(No version information available, might only be in Git)
CairoPatternType is used to describe the type of a given pattern.
The type of a pattern is determined by the function used to create it.
The cairo_pattern_create_rgb() and cairo_pattern_create_rgba()
functions create CairoPatternType::SOLID patterns. The remaining
cairo_pattern_create_* functions map to pattern types in obvious ways.
CairoPatternType::SOLIDThe pattern is a solid (uniform) color. It may be opaque or translucent.
CairoPatternType::SURFACEThe pattern is a based on a surface (an image).
CairoPatternType::LINEARThe pattern is a linear gradient.
CairoPatternType::RADIALThe pattern is a radial gradient.
(PECL cairo >= 0.1.0)
CairoPattern is the abstract base class from which all the other pattern classes derive. It cannot be instantiated directly
(PECL cairo >= 0.1.0)
CairoPattern::__construct — The __construct purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoPattern::__construct() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoPattern::getMatrix -- cairo_get_matrix — The getMatrix purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoPattern::getType — The getType purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoPattern::getType() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoPattern::setMatrix -- cairo_set_matrix — The setMatrix purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
matrixDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoPattern::status -- cairo_status — The status purpose
Object oriented style (method):
Procedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoGradientPattern is an abstract base class from which other Pattern classes derive. It cannot be instantiated directly.
$offset
, float $red
, float $green
, float $blue
, float $alpha
) : void(PECL cairo >= 0.1.0)
CairoGradientPattern::addColorStopRgb — The addColorStopRgb purpose
$offset
, float $red
, float $green
, float $blue
) : voidThe method description goes here.
This function is currently not documented; only its argument list is available.
offsetDescription...
redDescription...
greenDescription...
blueDescription...
Description...
Example #1 CairoGradientPattern::addColorStopRgb() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoGradientPattern::addColorStopRgba — The addColorStopRgba purpose
$offset
, float $red
, float $green
, float $blue
, float $alpha
) : voidThe method description goes here.
This function is currently not documented; only its argument list is available.
offsetDescription...
redDescription...
greenDescription...
blueDescription...
alphaDescription...
Description...
Example #1 CairoGradientPattern::addColorStopRgba() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoGradientPattern::getColorStopCount — The getColorStopCount purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoGradientPattern::getColorStopCount() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoGradientPattern::getColorStopRgba — The getColorStopRgba purpose
$index
) : arrayThe method description goes here.
This function is currently not documented; only its argument list is available.
indexDescription...
Description...
Example #1 CairoGradientPattern::getColorStopRgba() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoGradientPattern::getExtend — The getExtend purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoGradientPattern::getExtend() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoGradientPattern::setExtend — The setExtend purpose
$extend
) : voidThe method description goes here.
This function is currently not documented; only its argument list is available.
extendDescription...
Description...
Example #1 CairoGradientPattern::setExtend() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
(PECL cairo >= 0.1.0)
CairoSolidPattern::__construct — The __construct purpose
$red
, float $green
, float $blue
[, float $alpha = 0
] )The method description goes here.
This function is currently not documented; only its argument list is available.
redDescription...
greenDescription...
blueDescription...
alphaDescription...
Description...
Example #1 CairoSolidPattern::__construct() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoSolidPattern::getRgba — The getRgba purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoSolidPattern::getRgba() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
(PECL cairo >= 0.1.0)
CairoSurfacePattern::__construct — The __construct purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
surfaceDescription...
Description...
Example #1 CairoSurfacePattern::__construct() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoSurfacePattern::getExtend — The getExtend purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoSurfacePattern::getExtend() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoSurfacePattern::getFilter — The getFilter purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoSurfacePattern::getFilter() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoSurfacePattern::getSurface — The getSurface purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoSurfacePattern::getSurface() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoSurfacePattern::setExtend — The setExtend purpose
$extend
) : voidThe method description goes here.
This function is currently not documented; only its argument list is available.
extendDescription...
Description...
Example #1 CairoSurfacePattern::setExtend() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoSurfacePattern::setFilter — The setFilter purpose
$filter
) : voidThe method description goes here.
This function is currently not documented; only its argument list is available.
filterDescription...
Description...
Example #1 CairoSurfacePattern::setFilter() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
Create a new CairoLinearGradient along the line defined
$offset
, float $red
, float $green
, float $blue
) : void$offset
, float $red
, float $green
, float $blue
, float $alpha
) : void(PECL cairo >= 0.1.0)
CairoLinearGradient::__construct — The __construct purpose
$x0
, float $y0
, float $x1
, float $y1
)The method description goes here.
This function is currently not documented; only its argument list is available.
x0Description...
y0Description...
x1Description...
y1Description...
Description...
Example #1 CairoLinearGradient::__construct() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoLinearGradient::getPoints — The getPoints purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoLinearGradient::getPoints() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
$offset
, float $red
, float $green
, float $blue
) : void$offset
, float $red
, float $green
, float $blue
, float $alpha
) : void(PECL cairo >= 0.1.0)
CairoRadialGradient::__construct — The __construct purpose
Object oriented style:
$x0
, float $y0
, float $r0
, float $x1
, float $y1
, float $r1
)Procedural style:
Creates a new radial gradient CairoPattern between the two circles defined by (x0, y0, r0) and (x1, y1, r1). Before using the gradient pattern, a number of color stops should be defined using CairoRadialGradient::addColorStopRgb() or CairoRadialGradient::addColorStopRgba().
Note: The coordinates here are in pattern space. For a new pattern, pattern space is identical to user space, but the relationship between the spaces can be changed with CairoRadialGradient::setMatrix().
x0x coordinate for the center of the start circle.
y0y coordinate for the center of the start circle.
r0radius of the start circle.
x1x coordinate for the center of the end circle.
y1y coordinate for the center of the end circle.
r1radius of the end circle.
Description...
Example #1 CairoRadialGradient::__construct() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoRadialGradient::getCircles — The getCircles purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoRadialGradient::getCircles() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(No version information available, might only be in Git)
Enum class that specifies the type of antialiasing to do when rendering text or shapes.
CairoAntialias::MODE_DEFAULTUse the default antialiasing for the subsystem and target device
CairoAntialias::MODE_NONEUse a bilevel alpha mask
CairoAntialias::MODE_GRAYPerform single-color antialiasing (using shades of gray for black text on a white background, for example).
CairoAntialias::MODE_SUBPIXELPerform antialiasing by taking advantage of the order of subpixel elements on devices such as LCD panels.
(No version information available, might only be in Git)
CairoContent is used to describe the content that a surface will contain, whether color information, alpha information (translucence vs. opacity), or both.
Note: The large values here are designed to keep CairoContent values distinct from CairoContent values so that the implementation can detect the error if users confuse the two types.
CairoContent::COLORThe surface will hold color content only.
CairoContent::ALPHAThe surface will hold alpha content only.
CairoContent::COLOR_ALPHAThe surface will hold color and alpha content.
(No version information available, might only be in Git)
CairoExtend::NONEDescription here...
CairoExtend::REPEATDescription here...
CairoExtend::REFLECTDescription here...
CairoExtend::PADDescription here...
(PECL cairo >= 0.1.0)
CairoFormat enums are used to identify the memory format of the image data.
CairoFormat::ARGB32Each pixel is a 32-bit quantity, with alpha in the upper 8 bits, then red, then green, then blue. The 32-bit quantities are stored native-endian. Pre-multiplied alpha is used. (That is, 50% transparent red is 0x80800000, not 0x80ff0000.)
CairoFormat::RGB24Each pixel is a 32-bit quantity, with the upper 8 bits unused. Red, Green, and Blue are stored in the remaining 24 bits in that order.
CairoFormat::A8Each pixel is a 8-bit quantity holding an alpha value.
CairoFormat::A1Each pixel is a 1-bit quantity holding an alpha value. Pixels are packed together into 32-bit quantities. The ordering of the bits matches the endianness of the platform. On a big-endian machine, the first pixel is in the uppermost bit, on a little-endian machine the first pixel is in the least-significant bit.
(PECL cairo >= 0.1.0)
CairoFormat::strideForWidth — Provides an appropriate stride to use
$format
, int $width
) : intThis method provides a stride value that will respect all alignment requirements of the accelerated image-rendering code within cairo.
The appropriate stride to use given the desired format and width, or -1 if either the format is invalid or the width too large.
Example #1 CairoFormat::strideForWidth() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(No version information available, might only be in Git)
A CairoFillRule is used to select how paths are filled. For both fill rules, whether or not a point is included in the fill is determined by taking a ray from that point to infinity and looking at intersections with the path. The ray can be in any direction, as long as it doesn't pass through the end point of a segment or have a tricky intersection such as intersecting tangent to the path. (Note that filling is not actually implemented in this way. This is just a description of the rule that is applied.)
The default fill rule is CairoFillRule::WINDING.
CairoFillRule::WINDINGIf the path crosses the ray from left-to-right, counts +1. If the path crosses the ray from right to left, counts -1. (Left and right are determined from the perspective of looking along the ray from the starting point.) If the total count is non-zero, the point will be filled.
CairoFillRule::EVEN_ODDCounts the total number of intersections, without regard to the orientation of the contour. If the total number of intersections is odd, the point will be filled.
(No version information available, might only be in Git)
A CairoFilter is used to indicate what filtering should be applied when reading pixel values from patterns. See CairoPattern::setSource() or cairo_pattern_set_source() for indicating the desired filter to be used with a particular pattern.
CairoFilter::FAST A high-performance filter, with quality similar to CairoFilter::NEAREST
CairoFilter::GOODA reasonable-performance filter, with quality similar to CairoFilter::BILINEAR
CairoFilter::BESTThe highest-quality available, performance may not be suitable for interactive use.
CairoFilter::NEARESTNearest-neighbor filtering
CairoFilter::BILINEARLinear interpolation in two dimensions
CairoFilter::GAUSSIANThis filter value is currently unimplemented, and should not be used in current code.
(No version information available, might only be in Git)
Specifies whether to hint font metrics; hinting font metrics means quantizing them so that they are integer values in device space. Doing this improves the consistency of letter and line spacing, however it also means that text will be laid out differently at different zoom factors.
CairoHintMetrics::METRICS_DEFAULTHint metrics in the default manner for the font backend and target device
CairoHintMetrics::METRICS_OFFDo not hint font metrics
CairoHintMetrics::METRICS_ONHint font metrics
(No version information available, might only be in Git)
Specifies the type of hinting to do on font outlines. Hinting is the process of fitting outlines to the pixel grid in order to improve the appearance of the result. Since hinting outlines involves distorting them, it also reduces the faithfulness to the original outline shapes. Not all of the outline hinting styles are supported by all font backends.
CairoHintStyle::STYLE_DEFAULTUse the default hint style for font backend and target device
CairoHintStyle::STYLE_NONEDo not hint outlines
CairoHintStyle::STYLE_SLIGHTHint outlines slightly to improve contrast while retaining good fidelity to the original shapes.
CairoHintStyle::STYLE_MEDIUMHint outlines with medium strength giving a compromise between fidelity to the original shapes and contrast
CairoHintStyle::STYLE_FULLHint outlines to maximize contrast
(No version information available, might only be in Git)
Specifies how to render the endpoints of the path when stroking.
The default line cap style is CairoLineCap::BUTT.
CairoLineCap::BUTTStart(stop) the line exactly at the start(end) point
CairoLineCap::ROUNDUse a round ending, the center of the circle is the end point
CairoLineCap::SQUAREUse squared ending, the center of the square is the end point
(No version information available, might only be in Git)
CairoLineJoin::MITERDescription here...
CairoLineJoin::ROUNDDescription here...
CairoLineJoin::BEVELDescription here...
(PECL cairo >= 0.1.0)
Matrices are used throughout cairo to convert between different coordinate spaces.
$xx = 1.0
[, float $yx = 0.0
[, float $xy = 0.0
[, float $yy = 1.0
[, float $x0 = 0.0
[, float $y0 = 0.0
]]]]]] )(PECL cairo >= 0.1.0)
CairoMatrix::__construct -- cairo_matrix_init — Creates a new CairoMatrix object
Object oriented style (method):
$xx = 1.0
[, float $yx = 0.0
[, float $xy = 0.0
[, float $yy = 1.0
[, float $x0 = 0.0
[, float $y0 = 0.0
]]]]]] )Procedural style:
$xx = 1.0
[, float $yx = 0.0
[, float $xy = 0.0
[, float $yy = 1.0
[, float $x0 = 0.0
[, float $y0 = 0.0
]]]]]] ) : objectReturns new CairoMatrix object. Matrices are used throughout cairo to convert between different coordinate spaces. Sets matrix to be the affine transformation given by xx, yx, xy, yy, x0, y0. The transformation is given by: x_new = xx * x + xy * y + x0; and y_new = yx * x + yy * y + y0;
xxxx component of the affine transformation
yxyx component of the affine transformation
xyxy component of the affine transformation
yyyy component of the affine transformation
x0X translation component of the affine transformation
y0Y translation component of the affine transformation
Returns a new CairoMatrix object that can be used with surfaces, contexts, and patterns.
Example #1 Object oriented style
<?php
/* Create a new Matrix */
$matrix = new CairoMatrix(1.0, 0.5, 0.0, 1.0, 0.0, 0.0);
?>
Example #2 Procedural style
<?php
/* Create a new Matrix */
$matrix = cairo_matrix_init(1.0, 0.5, 0.0, 1.0, 0.0, 0.0);
?>
(PECL cairo >= 0.1.0)
CairoMatrix::initIdentity -- cairo_matrix_init_identity — Creates a new identity matrix
Object oriented style (method):
Procedural style:
Creates a new matrix that is an identity transformation. An identity transformation means the source data is copied into the destination data without change
This function has no parameters.
Returns a new CairoMatrix object that can be used with surfaces, contexts, and patterns.
Example #1 Object oriented style
<?php
/* Create a new Matrix */
$matrix = CairoMatrix::initIdentity();
?>
Example #2 Procedural style
<?php
/* Create a new Matrix */
$matrix = cairo_matrix_init_identity();
?>
(PECL cairo >= 0.1.0)
CairoMatrix::initRotate -- cairo_matrix_init_rotate — Creates a new rotated matrix
Object oriented style (method):
$radians
) : voidProcedural style:
$radians
) : objectCreates a new matrix to a transformation that rotates by radians provided
radiansangle of rotation, in radians. The direction of rotation is defined such that positive angles rotate in the direction from the positive X axis toward the positive Y axis. With the default axis orientation of cairo, positive angles rotate in a clockwise direction.
Returns a new CairoMatrix object that can be used with surfaces, contexts, and patterns.
Example #1 Object oriented style
<?php
/* Create a new Matrix */
$matrix = CairoMatrix::initRotate(0.3);
?>
Example #2 Procedural style
<?php
/* Create a new Matrix */
$matrix = cairo_matrix_init_rotate(0.3);
?>
(PECL cairo >= 0.1.0)
CairoMatrix::initScale -- cairo_matrix_init_scale — Creates a new scaling matrix
Object oriented style (method):
$sx
, float $sy
) : voidProcedural style:
$sx
, float $sy
) : objectCreates a new matrix to a transformation that scales by sx and sy in the X and Y dimensions, respectively.
sxscale factor in the X direction
syscale factor in the Y direction
Returns a new CairoMatrix object that can be used with surfaces, contexts, and patterns.
Example #1 Object oriented style
<?php
/* Create a new Matrix */
$matrix = CairoMatrix::initScale(1.0, 2.0);
?>
Example #2 Procedural style
<?php
/* Create a new Matrix */
$matrix = cairo_matrix_init_scale(1.0, 2.0);
?>
(PECL cairo >= 0.1.0)
CairoMatrix::initTranslate -- cairo_matrix_init_translate — Creates a new translation matrix
Object oriented style (method):
$tx
, float $ty
) : voidProcedural style:
$tx
, float $ty
) : objectCreates a new matrix to a transformation that translates by tx and ty in the X and Y dimensions, respectively.
txamount to translate in the X direction
tyamount to translate in the Y direction
Returns a new CairoMatrix object that can be used with surfaces, contexts, and patterns.
Example #1 Object oriented style
<?php
/* Create a new Matrix */
$matrix = CairoMatrix::initTranslate(1.0, 2.0);
?>
Example #2 Procedural style
<?php
/* Create a new Matrix */
$matrix = cairo_matrix_init_translate(1.0, 2.0);
?>
(PECL cairo >= 0.1.0)
CairoMatrix::invert — The invert purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
This function has no parameters.
Description...
Example #1 CairoMatrix::invert() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoMatrix::multiply — The multiply purpose
The method description goes here.
This function is currently not documented; only its argument list is available.
matrix1Description...
matrix2Description...
Description...
Example #1 CairoMatrix::multiply() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoMatrix::rotate -- cairo_matrix_rotate — The rotate purpose
Object oriented style (method):
$radians
) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
radiansDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoMatrix::scale -- cairo_matrix_scale — Applies scaling to a matrix
Object oriented style (method):
$sx
, float $sy
) : voidProcedural style:
Applies scaling by sx, sy to the transformation in the matrix. The effect of the new transformation is to first scale the coordinates by sx and sy, then apply the original transformation to the coordinates.
matrixProcedural only - CairoMatrix instance
sxscale factor in the X direction
syscale factor in the Y direction
Example #1 Object oriented style
<?php
/* Apply scaling to a matrix */
$matrix = new CairoMatrix(1.0, 0.5, 0.0, 1.0, 0.0, 0.0);
$matrix->scale(0.2, 2.0);
?>
Example #2 Procedural style
<?php
/* Apply scaling to a matrix */
$matrix = cairo_matrix_init(1.0, 0.5, 0.0, 1.0, 0.0, 0.0);
cairo_matrix_scale($matrix, 0.2, 2.0);
?>
(PECL cairo >= 0.1.0)
CairoMatrix::transformDistance — The transformDistance purpose
$dx
, float $dy
) : arrayThe method description goes here.
This function is currently not documented; only its argument list is available.
dxDescription...
dyDescription...
Description...
Example #1 CairoMatrix::transformDistance() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoMatrix::transformPoint — The transformPoint purpose
$dx
, float $dy
) : arrayThe method description goes here.
This function is currently not documented; only its argument list is available.
dxDescription...
dyDescription...
Description...
Example #1 CairoMatrix::transformPoint() example
<?php
/* ... */
?>
The above example will output something similar to:
...
(PECL cairo >= 0.1.0)
CairoMatrix::translate -- cairo_translate — The translate purpose
Object oriented style (method):
$tx
, float $ty
) : voidProcedural style:
Description here.
This function is currently not documented; only its argument list is available.
contextDescription...
xDescription...
yDescription...
txDescription...
tyDescription...
Description...
Example #1 Object oriented style
<?php
/* ... */
?>
The above example will output something similar to:
...
Example #2 Procedural style
<?php
/* ... */
?>
The above example will output something similar to:
...
(No version information available, might only be in Git)
This is used to set the compositing operator for all cairo drawing operations.
The default operator is CairoOperator::OVER
The operators marked as unbounded modify their destination even outside of the mask layer (that is, their effect is not bound by the mask layer). However, their effect can still be limited by way of clipping.
To keep things simple, the operator descriptions here document the behavior for when both source and destination are either fully transparent or fully opaque. The actual implementation works for translucent layers too. For a more detailed explanation of the effects of each operator, including the mathematical definitions, see http://cairographics.org/operators/.
CairoOperator::CLEARClear destination layer (bounded)
CairoOperator::SOURCEReplace destination layer (bounded)
CairoOperator::OVERDraw source layer on top of destination layer (bounded)
CairoOperator::INDraw source where there was destination content (unbounded)
CairoOperator::OUTDraw source where there was no destination content (unbounded)
CairoOperator::ATOPDraw source on top of destination content and only there
CairoOperator::DESTIgnore the source
CairoOperator::DEST_OVERDraw destination on top of source
CairoOperator::DEST_INLeave destination only where there was source content (unbounded)
CairoOperator::DEST_OUTLeave destination only where there was no source content
CairoOperator::DEST_ATOPLeave destination on top of source content and only there (unbounded)
CairoOperator::XORSource and destination are shown where there is only one of them
CairoOperator::ADDSource and destination layers are accumulated
CairoOperator::SATURATELike CairoOperator::OVER, but assuming source and dest are disjoint geometries
(No version information available, might only be in Git)
Note: CairoPath class cannot be instantiated directly, doing so will result in Fatal Error if used or passed
(No version information available, might only be in Git)
CairoPsLevel::LEVEL_2Description here...
CairoPsLevel::LEVEL_3Description here...
(No version information available, might only be in Git)
CairoSubpixelOrder::ORDER_DEFAULTDescription here...
CairoSubpixelOrder::ORDER_RGBDescription here...
CairoSubpixelOrder::ORDER_BGRDescription here...
CairoSubpixelOrder::ORDER_VRGBDescription here...
CairoSubpixelOrder::ORDER_VBGRDescription here...
(No version information available, might only be in Git)
CairoSvgVersion::VERSION_1_1Description here...
CairoSvgVersion::VERSION_1_2Description here...
With the exif extension you are able to work with image meta data. For example, you may use exif functions to read meta data of pictures taken from digital cameras by working with information stored in the headers. These are commonly found in JPEG and TIFF images.
Your PHP must be compiled in with --enable-exif. To enable
multibyte support in EXIF tags, the mbstring
extension must be enabled by compiling PHP with --enable-mbstring.
PHP does not require any additional library for the exif module.
Windows only: The mbstring extension must always be enabled. Note that mbstring extension must be loaded prior to EXIF in php.ini.
To enable exif-support configure PHP with --enable-exif
Windows users must enable both the php_mbstring.dll and php_exif.dll DLL's in php.ini. The php_mbstring.dll DLL must be loaded before the php_exif.dll DLL so adjust your php.ini accordingly.
The behaviour of these functions is affected by settings in php.ini.
Exif supports automatically conversion for Unicode and JIS
character encodings of user comments when module
mbstring
is available. This is done by first decoding the comment
using the specified characterset. The result is then encoded
with another characterset which should match your
HTTP output.
| Name | Default | Changeable | Changelog |
|---|---|---|---|
| exif.encode_unicode | "ISO-8859-15" | PHP_INI_ALL | |
| exif.decode_unicode_motorola | "UCS-2BE" | PHP_INI_ALL | |
| exif.decode_unicode_intel | "UCS-2LE" | PHP_INI_ALL | |
| exif.encode_jis | "" | PHP_INI_ALL | |
| exif.decode_jis_motorola | "JIS" | PHP_INI_ALL | |
| exif.decode_jis_intel | "JIS" | PHP_INI_ALL |
Here's a short explanation of the configuration directives.
exif.encode_unicode
string
exif.encode_unicode defines the
characterset UNICODE user comments are handled.
This defaults to ISO-8859-15 which should work for
most non Asian countries. The setting can be empty
or must be an encoding supported by mbstring. If it
is empty the current internal encoding of mbstring is
used.
exif.decode_unicode_motorola
string
exif.decode_unicode_motorola defines
the image internal characterset for Unicode encoded user
comments if image is in motorola byte order (big-endian).
This setting cannot be empty but you can specify a list
of encodings supported by mbstring. The default is UCS-2BE.
exif.decode_unicode_intel
string
exif.decode_unicode_intel defines
the image internal characterset for Unicode encoded user
comments if image is in intel byte order (little-endian).
This setting cannot be empty but you can specify a list
of encodings supported by mbstring. The default is UCS-2LE.
exif.encode_jis
string
exif.encode_jis defines the
characterset JIS user comments are handled.
This defaults to an empty value which forces
the functions to use the current internal encoding
of mbstring.
exif.decode_jis_motorola
string
exif.decode_jis_motorola defines
the image internal characterset for JIS encoded user
comments if image is in motorola byte order (big-endian).
This setting cannot be empty but you can specify a list
of encodings supported by mbstring. The default is JIS.
exif.decode_jis_intel
string
exif.decode_jis_intel defines
the image internal characterset for JIS encoded user
comments if image is in intel byte order (little-endian).
This setting cannot be empty but you can specify a list
of encodings supported by mbstring. The default is JIS.
This extension has no resource types defined.
The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.
EXIF_USE_MBSTRING
(integer)
1 if the
mbstring is enabled, otherwise
it has a value of 0.
The exif_imagetype() lists several related built-in constants.
(PHP 4 >= 4.3.0, PHP 5, PHP 7)
exif_imagetype — Determine the type of an image
$filename
) : intexif_imagetype() reads the first bytes of an image and checks its signature.
exif_imagetype() can be used to avoid calls to other exif functions with unsupported file types or in conjunction with $_SERVER['HTTP_ACCEPT'] to check whether or not the viewer is able to see a specific image in the browser.
filename
When a correct signature is found, the appropriate constant value will be
returned otherwise the return value is FALSE. The return value is the
same value that getimagesize() returns in index 2 but
exif_imagetype() is much faster.
Note:
exif_imagetype() will emit an
E_NOTICEand returnFALSEif it is unable to read enough bytes from the file to determine the image type.
| Version | Description |
|---|---|
| 7.1.0 | Added WebP support. |
| 5.3.0 | Added icon support. |
The following constants are defined, and represent possible exif_imagetype() return values:
| Value | Constant |
|---|---|
| 1 | IMAGETYPE_GIF |
| 2 | IMAGETYPE_JPEG |
| 3 | IMAGETYPE_PNG |
| 4 | IMAGETYPE_SWF |
| 5 | IMAGETYPE_PSD |
| 6 | IMAGETYPE_BMP |
| 7 | IMAGETYPE_TIFF_II (intel byte order) |
| 8 |
IMAGETYPE_TIFF_MM (motorola byte order)
|
| 9 | IMAGETYPE_JPC |
| 10 | IMAGETYPE_JP2 |
| 11 | IMAGETYPE_JPX |
| 12 | IMAGETYPE_JB2 |
| 13 | IMAGETYPE_SWC |
| 14 | IMAGETYPE_IFF |
| 15 | IMAGETYPE_WBMP |
| 16 | IMAGETYPE_XBM |
| 17 | IMAGETYPE_ICO |
| 18 | IMAGETYPE_WEBP |
Example #1 exif_imagetype() example
<?php
if (exif_imagetype('image.gif') != IMAGETYPE_GIF) {
echo 'The picture is not a gif';
}
?>
(PHP 4 >= 4.2.0, PHP 5, PHP 7)
exif_read_data — Reads the EXIF headers from an image file
$stream
[, string $sections = NULL
[, bool $arrays = FALSE
[, bool $thumbnail = FALSE
]]] ) : arrayexif_read_data() reads the EXIF headers from an image file. This way you can read meta data generated by digital cameras.
EXIF headers tend to be present in JPEG/TIFF images generated by digital cameras, but unfortunately each digital camera maker has a different idea of how to actually tag their images, so you can't always rely on a specific Exif header being present.
Height and Width are computed the
same way getimagesize() does so their values must not be
part of any header returned. Also, html is a
height/width text string to be used inside normal HTML.
When an Exif header contains a Copyright note, this itself can contain two
values. As the solution is inconsistent in the Exif 2.10 standard, the
COMPUTED section will return both entries
Copyright.Photographer and
Copyright.Editor while the IFD0
sections contains the byte array with the NULL character that splits both
entries. Or just the first entry if the datatype was wrong (normal behaviour
of Exif). The COMPUTED will also contain the entry
Copyright which is either the original copyright string,
or a comma separated list of the photo and editor copyright.
The tag UserComment has the same problem as the Copyright
tag. It can store two values. First the encoding used, and second the value
itself. If so the IFD section only contains the encoding
or a byte array. The COMPUTED section will store both in
the entries UserCommentEncoding and
UserComment. The entry UserComment
is available in both cases so it should be used in preference to the value
in IFD0 section.
exif_read_data() also validates EXIF data tags according to the EXIF specification (» http://exif.org/Exif2-2.PDF, page 20).
Note:
Windows Me/XP can both wipe the Exif headers when connecting to a camera.
streamThe location of the image file. This can either be a path to the file (stream wrappers are also supported as usual) or a stream resource.
sections
Is a comma separated list of sections that need to be present in file
to produce a result array. If none of the requested
sections could be found the return value is FALSE.
| FILE | FileName, FileSize, FileDateTime, SectionsFound |
| COMPUTED |
html, Width, Height, IsColor, and more if available. Height and
Width are computed the same way getimagesize()
does so their values must not be part of any header returned.
Also, html is a height/width text string to be used inside normal
HTML.
|
| ANY_TAG | Any information that has a Tag e.g. IFD0, EXIF, ... |
| IFD0 | All tagged data of IFD0. In normal imagefiles this contains image size and so forth. |
| THUMBNAIL |
A file is supposed to contain a thumbnail if it has a second IFD.
All tagged information about the embedded thumbnail is stored in
this section.
|
| COMMENT | Comment headers of JPEG images. |
| EXIF |
The EXIF section is a sub section of IFD0. It contains
more detailed information about an image. Most of these entries
are digital camera related.
|
arrays
Specifies whether or not each section becomes an array. The
sections COMPUTED,
THUMBNAIL, and COMMENT
always become arrays as they may contain values whose names conflict
with other sections.
thumbnail
When set to TRUE the thumbnail itself is read. Otherwise, only the
tagged data is read.
It returns an associative array where the array indexes are
the header names and the array values are the values associated with
those headers. If no data can be returned,
exif_read_data() will return FALSE.
| Version | Description |
|---|---|
| 7.2.0 |
The filename parameter was renamed to
stream and now supports both local files
or stream resources.
|
| 7.2.0 |
Support for the following EXIF formats were added:
|
Example #1 exif_read_data() example
<?php
echo "test1.jpg:<br />\n";
$exif = exif_read_data('tests/test1.jpg', 'IFD0');
echo $exif===false ? "No header data found.<br />\n" : "Image contains headers<br />\n";
$exif = exif_read_data('tests/test2.jpg', 0, true);
echo "test2.jpg:<br />\n";
foreach ($exif as $key => $section) {
foreach ($section as $name => $val) {
echo "$key.$name: $val<br />\n";
}
}
?>
The first call fails because the image has no header information.
The above example will output something similar to:
test1.jpg: No header data found. test2.jpg: FILE.FileName: test2.jpg FILE.FileDateTime: 1017666176 FILE.FileSize: 1240 FILE.FileType: 2 FILE.SectionsFound: ANY_TAG, IFD0, THUMBNAIL, COMMENT COMPUTED.html: width="1" height="1" COMPUTED.Height: 1 COMPUTED.Width: 1 COMPUTED.IsColor: 1 COMPUTED.ByteOrderMotorola: 1 COMPUTED.UserComment: Exif test image. COMPUTED.UserCommentEncoding: ASCII COMPUTED.Copyright: Photo (c) M.Boerger, Edited by M.Boerger. COMPUTED.Copyright.Photographer: Photo (c) M.Boerger COMPUTED.Copyright.Editor: Edited by M.Boerger. IFD0.Copyright: Photo (c) M.Boerger IFD0.UserComment: ASCII THUMBNAIL.JPEGInterchangeFormat: 134 THUMBNAIL.JPEGInterchangeFormatLength: 523 COMMENT.0: Comment #1. COMMENT.1: Comment #2. COMMENT.2: Comment #3end THUMBNAIL.JPEGInterchangeFormat: 134 THUMBNAIL.Thumbnail.Height: 1 THUMBNAIL.Thumbnail.Height: 1
Example #2 exif_read_data() with streams available as of PHP 7.2.0
<?php
// Open a the file, this should be in binary mode
$fp = fopen('/path/to/image.jpg', 'rb');
if (!$fp) {
echo 'Error: Unable to open image for reading';
exit;
}
// Attempt to read the exif headers
$headers = exif_read_data($fp);
if (!$headers) {
echo 'Error: Unable to read exif headers';
exit;
}
// Print the 'COMPUTED' headers
echo 'EXIF Headers:' . PHP_EOL;
foreach ($headers['COMPUTED'] as $header => $value) {
printf(' %s => %s%s', $header, $value, PHP_EOL);
}
?>
The above example will output something similar to:
EXIF Headers:
Height => 576
Width => 1024
IsColor => 1
ByteOrderMotorola => 0
ApertureFNumber => f/5.6
UserComment =>
UserCommentEncoding => UNDEFINED
Copyright => Denis
Thumbnail.FileType => 2
Thumbnail.MimeType => image/jpeg
Note:
If mbstring is enabled, exif will attempt to process the unicode and pick a charset as specified by exif.decode_unicode_motorola and exif.decode_unicode_intel. The exif extension will not attempt to figure out the encoding on its own, and it is up to the user to properly specify the encoding for which to use for decoding by setting one of these two ini directives prior to calling exif_read_data().
Note:
If the
streamis used to pass a stream to this function, then the stream must be seekable. Note that the file pointer position is not changed after this function returns.
(PHP 4 >= 4.2.0, PHP 5, PHP 7)
exif_tagname — Get the header name for an index
$index
) : string
indexThe Tag ID for which a Tag Name will be looked up.
Returns the header name, or FALSE if index is
not a defined EXIF tag id.
Example #1 exif_tagname() example
<?php
echo "256: ".exif_tagname(256).PHP_EOL;
echo "257: ".exif_tagname(257).PHP_EOL;
?>
The above example will output:
256: ImageWidth 257: ImageLength
(PHP 4 >= 4.2.0, PHP 5, PHP 7)
exif_thumbnail — Retrieve the embedded thumbnail of an image
exif_thumbnail() reads the embedded thumbnail of an image.
If you want to deliver thumbnails through this function, you should send the mimetype information using the header() function.
It is possible that exif_thumbnail() cannot create an
image but can determine its size. In this case, the return value is
FALSE but width and height
are set.
streamThe location of the image file. This can either be a path to the file or a stream resource.
widthThe return width of the returned thumbnail.
heightThe returned height of the returned thumbnail.
imagetypeThe returned image type of the returned thumbnail. This is either TIFF or JPEG.
Returns the embedded thumbnail, or FALSE if the image contains no
thumbnail.
Example #1 exif_thumbnail() example
<?php
$image = exif_thumbnail('/path/to/image.jpg', $width, $height, $type);
if ($image!==false) {
header('Content-type: ' .image_type_to_mime_type($type));
echo $image;
exit;
} else {
// no thumbnail available, handle the error here
echo 'No thumbnail available';
}
?>
| Version | Description |
|---|---|
| 7.2.0 |
The filename parameter was renamed to
stream and now supports both local files
or stream resources.
|
Note:
If the
streamis used to pass a stream to this function, then the stream must be seekable. Note that the file pointer position is not changed after this function returns.
This function is an alias of: exif_read_data().
| Version | Description |
|---|---|
| 7.2.0 | This function alias was deprecated. |
PHP is not limited to creating just HTML output. It can also be used to create and manipulate image files in a variety of different image formats, including GIF, PNG, JPEG, WBMP, and XPM. Even more conveniently, PHP can output image streams directly to a browser. You will need to compile PHP with the GD library of image functions for this to work. GD and PHP may also require other libraries, depending on which image formats you want to work with.
You can use the image functions in PHP to get the size of JPEG, GIF, PNG, SWF, TIFF and JPEG2000 images.
With the exif extension, you are able to work with information stored in headers of JPEG and TIFF images. This way you can read meta data generated by digital cameras. The exif functions do not require the GD library.
Note: Read the requirements section about how to expand image capabilities to read, write and modify images. To read meta data of pictures taken by digital cameras you need the above mentioned exif extension.
Note: The getimagesize() function does not require the GD extension.
While the bundled version of the GD library uses the Zend memory manager to allocate memory, system versions do not, so that memory_limit does not apply.
GD supports a varity of formats, below is a list of formats supported by GD and notes to their availability including read/write support.
| Format | Read support | Write support | Notes |
|---|---|---|---|
| JPEG | TRUE |
TRUE |
|
| PNG | TRUE |
TRUE |
|
| GIF | TRUE |
TRUE |
Available as of GD 2.0.28 and PHP 5.0.1 |
| XBM | TRUE |
TRUE |
|
| XPM | TRUE |
FALSE |
Read support available on Windows as of PHP 5.3.19. |
| WBMP | TRUE |
TRUE |
|
| WebP | TRUE |
TRUE |
PHP 5.4+ |
| BMP | TRUE |
TRUE |
Available as of GD 2.1.0 and PHP 7.2.0 |
Despite most formats being available for both reading and writing in the above table, doesn't mean that PHP was compiled with support for them. To find out which formats that was available to GD during compilation, use the gd_info() function, for more information about compiling support for one or more formats, see the installation chapter.
If you have the GD library (available at » http://www.libgd.org/) you will also be able to create and manipulate images.
The format of images you are able to manipulate depend on the version of GD you install, and any other libraries GD might need to access those image formats. GIF support is available as of gd-2.0.28.
Note: libgd-2.0.4 or higher is required. As of PHP 5.5 libgd-2.1.0 or higher is required. Alternatively, use the bundled GD library that ships with PHP.
You may wish to enhance GD to handle more image formats.
| Image format | Library to download | Notes |
|---|---|---|
gif |
Only supported in GD versions newer than gd-2.0.28. Write support is available as of PHP 5.0.1. | |
jpeg |
» http://www.ijg.org/ |
When building the jpeg library (prior to building PHP) you
must use the --enable-shared
option in the configure step. If you do not, you will receive
an error saying libjpeg.(a|so) not found
when you get to the configure step of building PHP.
|
png |
» http://www.libpng.org/pub/png/libpng.html | |
xpm |
» ftp://metalab.unc.edu/pub/Linux/libs/X/!INDEX.html | It's likely you have this library already available, if your system has an installed X-Environment. |
You may wish to enhance GD to deal with different fonts. The following font libraries are supported:
| Font library | Download | Notes |
|---|---|---|
FreeType 1.x |
» http://www.freetype.org/ | Support for FreeType 1.x has been removed as of PHP 5.3.0. |
FreeType 2 |
» http://www.freetype.org/ | |
T1lib |
» ftp://sunsite.unc.edu/pub/Linux/libs/graphics/) | Support for Postscript Type 1 fonts (Removed as of PHP 7.0.0). |
To enable GD-support configure PHP --with-gd[=DIR], where DIR is the GD base install directory. To use the recommended bundled version of the GD library, use the configure option --with-gd. GD library requires libpng and libjpeg to compile. As of PHP 7.4.0, --with-gd becomes --enable-gd (whether to enable the extension at all) and --with-external-gd (to opt into using an external libgd, rather than the bundled one).
In Windows, you'll include the GD2 DLL php_gd2.dll as an extension in php.ini.
Enhance the capabilities of GD to handle more image formats by specifying
the --with-XXXX configure switch to your PHP configure
line.
| Image Format | Configure Switch |
|---|---|
jpeg |
To enable support for jpeg add --with-jpeg-dir=DIR. Jpeg 6b, 7 or 8 are supported. As of PHP 7.4.0, use --with-jpeg instead. |
png |
To enable support for png add --with-png-dir=DIR. Note, libpng requires the zlib library, therefore add --with-zlib-dir[=DIR] to your configure line. As of PHP 7.4.0, --with-png-dir and --with-zlib-dir have been removed. libpng and zlib are required. |
xpm |
To enable support for xpm add --with-xpm-dir=DIR. If configure is not able to find the required libraries, you may add the path to your X11 libraries. As of PHP 7.4.0, use --with-xpm instead. |
webp |
To enable support for webp add --with-vpx-dir=DIR. Available as of PHP 5.4.0. As of PHP 7.0.0 --with-webp-dir=DIR has to be added, i.e. support for libvpx has been removed in favor of libwebp. As of PHP 7.4.0, use --with-webp instead. |
Note: When compiling PHP with libpng, you must use the same version that was linked with the GD library.
Enhance the capabilities of GD to deal with different fonts by specifying
the --with-XXXX configure switch to your PHP configure
line.
| Font library | Configure Switch |
|---|---|
FreeType 2 |
To enable support for FreeType 2 add --with-freetype-dir=DIR. As of PHP 7.4.0 use --with-freetype instead, which relies on pkg-config. |
T1lib |
To enable support for T1lib (Postscript Type 1 fonts) add --with-t1lib[=DIR] (Removed as of PHP 7.0.0). |
Native TrueType string function |
To enable support for native TrueType string function add --enable-gd-native-ttf. (Effectless as of PHP 5.5.0; removed as of PHP 7.2.0.) |
The behaviour of these functions is affected by settings in php.ini.
| Name | Default | Changeable | Changelog |
|---|---|---|---|
| gd.jpeg_ignore_warning | "1" | PHP_INI_ALL | Available since PHP 5.1.3. |
Here's a short explanation of the configuration directives.
gd.jpeg_ignore_warning
bool
Ignore warnings (but not errors) created by libjpeg(-turbo).
| Version | Description |
|---|---|
| 7.1.0 | The default of gd.jpeg_ignore_warning has been changed from 0 to 1. |
See also the exif configuration directives.
Image functions are very memory intensive. Be sure to set memory_limit high enough, if you are using the bundled version of the GD library.
This extension defines the following resource types:
| Name | Description | Notes |
|---|---|---|
gd |
Image resource, used by functions like imagecreatefrompng() | |
gd font |
Font resource internally created by imageloadfont() | |
gd PS font |
PostScript Type 1 font resource, returned by imagepsloadfont() | Removed as of PHP 7.0.0. |
gd PS encoding |
PostScript Type 1 encoding resource, returned by imagepsencodefont() | Removed as of PHP 7.0.0. |
The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.
GD_VERSION
(string)
GD_MAJOR_VERSION
(integer)
GD_MINOR_VERSION
(integer)
GD_RELEASE_VERSION
(integer)
GD_EXTRA_VERSION
(string)
GD_BUNDLED
(integer)
IMG_BMP
(integer)
IMG_GIF
(integer)
IMG_JPG
(integer)
IMG_JPEG
(integer)
Note:
This constant has the same value as
IMG_JPG
IMG_PNG
(integer)
IMG_WBMP
(integer)
IMG_XPM
(integer)
IMG_WEBP
(integer)
IMG_COLOR_TILED
(integer)
IMG_COLOR_STYLED
(integer)
IMG_COLOR_BRUSHED
(integer)
IMG_COLOR_STYLEDBRUSHED
(integer)
IMG_COLOR_TRANSPARENT
(integer)
IMG_AFFINE_TRANSLATE
(integer)
IMG_AFFINE_SCALE
(integer)
IMG_AFFINE_ROTATE
(integer)
IMG_AFFINE_SHEAR_HORIZONTAL
(integer)
IMG_AFFINE_SHEAR_VERTICAL
(integer)
IMG_ARC_ROUNDED
(integer)
Note:
This constant has the same value as
IMG_ARC_PIE
IMG_ARC_PIE
(integer)
IMG_ARC_CHORD
(integer)
IMG_ARC_NOFILL
(integer)
IMG_ARC_EDGED
(integer)
IMG_GD2_RAW
(integer)
IMG_GD2_COMPRESSED
(integer)
IMG_EFFECT_REPLACE
(integer)
IMG_EFFECT_ALPHABLEND
(integer)
IMG_EFFECT_NORMAL
(integer)
IMG_EFFECT_OVERLAY
(integer)
IMG_EFFECT_MULTIPLY
(integer)
IMG_FILTER_NEGATE
(integer)
IMG_FILTER_GRAYSCALE
(integer)
IMG_FILTER_BRIGHTNESS
(integer)
IMG_FILTER_CONTRAST
(integer)
IMG_FILTER_COLORIZE
(integer)
IMG_FILTER_EDGEDETECT
(integer)
IMG_FILTER_GAUSSIAN_BLUR
(integer)
IMG_FILTER_SELECTIVE_BLUR
(integer)
IMG_FILTER_EMBOSS
(integer)
IMG_FILTER_MEAN_REMOVAL
(integer)
IMG_FILTER_SMOOTH
(integer)
IMG_FILTER_PIXELATE
(integer)
IMG_FILTER_SCATTER
(integer)
IMAGETYPE_GIF
(integer)
IMAGETYPE_JPEG
(integer)
IMAGETYPE_JPEG2000
(integer)
IMAGETYPE_PNG
(integer)
IMAGETYPE_SWF
(integer)
IMAGETYPE_PSD
(integer)
IMAGETYPE_BMP
(integer)
IMAGETYPE_WBMP
(integer)
IMAGETYPE_XBM
(integer)
IMAGETYPE_TIFF_II
(integer)
IMAGETYPE_TIFF_MM
(integer)
IMAGETYPE_IFF
(integer)
IMAGETYPE_JB2
(integer)
IMAGETYPE_JPC
(integer)
IMAGETYPE_JP2
(integer)
IMAGETYPE_JPX
(integer)
IMAGETYPE_SWC
(integer)
IMAGETYPE_ICO
(integer)
IMAGETYPE_WEBP
(integer)
PNG_NO_FILTER
(integer)
PNG_FILTER_NONE
(integer)
PNG_FILTER_SUB
(integer)
PNG_FILTER_UP
(integer)
PNG_FILTER_AVG
(integer)
PNG_FILTER_PAETH
(integer)
PNG_ALL_FILTERS
(integer)
IMG_FLIP_VERTICAL
(int)
IMG_FLIP_HORIZONTAL
(int)
IMG_FLIP_BOTH
(int)
IMG_BELL
(int)
IMG_BESSEL
(int)
IMG_BILINEAR_FIXED
(int)
IMG_BICUBIC
(int)
IMG_BICUBIC_FIXED
(int)
IMG_BLACKMAN
(int)
IMG_BOX
(int)
IMG_BSPLINE
(int)
IMG_CATMULLROM
(int)
IMG_GAUSSIAN
(int)
IMG_GENERALIZED_CUBIC
(int)
IMG_HERMITE
(int)
IMG_HAMMING
(int)
IMG_HANNING
(int)
IMG_MITCHELL
(int)
IMG_POWER
(int)
IMG_QUADRATIC
(int)
IMG_SINC
(int)
IMG_NEAREST_NEIGHBOUR
(int)
IMG_WEIGHTED4
(int)
IMG_TRIANGLE
(int)
Example #1 PNG creation with PHP
<?php
header("Content-type: image/png");
$string = $_GET['text'];
$im = imagecreatefrompng("images/button1.png");
$orange = imagecolorallocate($im, 220, 210, 60);
$px = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, 9, $string, $orange);
imagepng($im);
imagedestroy($im);
?>
<img
src="button.php?text=text">. The above button.php script
then takes this "text" string and overlays it on top of a
base image which in this case is "images/button1.png"
and outputs the resulting image. This is a very convenient way to
avoid having to draw new button images every time you want to
change the text of a button. With this method they are
dynamically generated.
Example #1 Adding watermarks to images using alpha channels
<?php
// Load the stamp and the photo to apply the watermark to
$stamp = imagecreatefrompng('stamp.png');
$im = imagecreatefromjpeg('photo.jpeg');
// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Copy the stamp image onto our photo using the margin offsets and the photo
// width to calculate positioning of the stamp.
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
// Output and free memory
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
Example #1 Using imagecopymerge() to create a translucent watermark
<?php
// Load the stamp and the photo to apply the watermark to
$im = imagecreatefromjpeg('photo.jpeg');
// First we create our stamp image manually from GD
$stamp = imagecreatetruecolor(100, 70);
imagefilledrectangle($stamp, 0, 0, 99, 69, 0x0000FF);
imagefilledrectangle($stamp, 9, 9, 90, 60, 0xFFFFFF);
imagestring($stamp, 5, 20, 20, 'libGD', 0x0000FF);
imagestring($stamp, 3, 20, 40, '(c) 2007-9', 0x0000FF);
// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Merge the stamp onto our photo with an opacity of 50%
imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50);
// Save the image to file and free memory
imagepng($im, 'photo_stamp.png');
imagedestroy($im);
?>
(PHP 4 >= 4.3.0, PHP 5, PHP 7)
gd_info — Retrieve information about the currently installed GD library
Gets information about the version and capabilities of the installed GD library.
Returns an associative array.
| Attribute | Meaning |
|---|---|
| GD Version | string value describing the installed
libgd version. |
| FreeType Support | boolean value. TRUE
if FreeType Support is installed. |
| FreeType Linkage | string value describing the way in which
FreeType was linked. Expected values are: 'with freetype',
'with TTF library', and 'with unknown library'. This element will
only be defined if FreeType Support evaluated to
TRUE. |
| T1Lib Support | boolean value. TRUE
if T1Lib support is included. |
| GIF Read Support | boolean value. TRUE
if support for reading GIF
images is included. |
| GIF Create Support | boolean value. TRUE
if support for creating GIF
images is included. |
| JPEG Support | boolean value. TRUE
if JPEG support is included. |
| PNG Support | boolean value. TRUE
if PNG support is included. |
| WBMP Support | boolean value. TRUE
if WBMP support is included. |
| XBM Support | boolean value. TRUE
if XBM support is included. |
| WebP Support | boolean value. TRUE
if WebP support is included. |
Note:
Previous to PHP 5.3.0, the
JPEG Supportattribute was namedJPG Support.
| Version | Description |
|---|---|
| 5.6.12 |
WebP Support added.
|
| 5.3.0 |
JPG Support attribute renamed to JPEG Support.
|
Example #1 Using gd_info()
<?php
var_dump(gd_info());
?>
The above example will output something similar to:
array(10) {
["GD Version"]=>
string(24) "bundled (2.1.0 compatible)"
["FreeType Support"]=>
bool(false)
["T1Lib Support"]=>
bool(false)
["GIF Read Support"]=>
bool(true)
["GIF Create Support"]=>
bool(false)
["JPEG Support"]=>
bool(false)
["PNG Support"]=>
bool(true)
["WBMP Support"]=>
bool(true)
["XBM Support"]=>
bool(false)
["WebP Support"]=>
bool(false)
}
(PHP 4, PHP 5, PHP 7)
getimagesize — Get the size of an image
$filename
[, array &$imageinfo
] ) : array
The getimagesize() function will determine the
size of any supported given image file and return the dimensions along with
the file type and a height/width text string to be used inside a
normal HTML IMG tag and the
correspondent HTTP content type.
getimagesize() can also return some more information
in imageinfo parameter.
This function expects filename to be a valid
image file. If a non-image file is supplied, it may be incorrectly
detected as an image and the function will return successfully, but
the array may contain nonsensical values.
Do not use getimagesize() to check that a given file is a valid image. Use a purpose-built solution such as the Fileinfo extension instead.
Note: Note that JPC and JP2 are capable of having components with different bit depths. In this case, the value for "bits" is the highest bit depth encountered. Also, JP2 files may contain
multiple JPEG 2000 codestreams. In this case, getimagesize() returns the values for the first codestream it encounters in the root of the file.
Note: The information about icons are retrieved from the icon with the highest bitrate.
Note: GIF images consist of one or more frames, where each frame may only occupy part of the image. The size of the image which is reported by getimagesize() is the overall size (read from the logical screen descriptor).
filenameThis parameter specifies the file you wish to retrieve information about. It can reference a local file or (configuration permitting) a remote file using one of the supported streams.
imageinfoThis optional parameter allows you to extract some extended information from the image file. Currently, this will return the different JPG APP markers as an associative array. Some programs use these APP markers to embed text information in images. A very common one is to embed » IPTC information in the APP13 marker. You can use the iptcparse() function to parse the binary APP13 marker into something readable.
Note:
The
imageinfoonly supports JFIF files.
Returns an array with up to 7 elements. Not all image types will include
the channels and bits elements.
Index 0 and 1 contains respectively the width and the height of the image.
Note:
Some formats may contain no image or may contain multiple images. In these cases, getimagesize() might not be able to properly determine the image size. getimagesize() will return zero for width and height in these cases.
Index 2 is one of the IMAGETYPE_XXX constants indicating the type of the image.
Index 3 is a text string with the correct
height="yyy" width="xxx" string that can be used
directly in an IMG tag.
mime is the correspondant MIME type of the image.
This information can be used to deliver images with the correct HTTP
Content-type header:
Example #1 getimagesize() and MIME types
<?php
$size = getimagesize($filename);
$fp = fopen($filename, "rb");
if ($size && $fp) {
header("Content-type: {$size['mime']}");
fpassthru($fp);
exit;
} else {
// error
}
?>
channels will be 3 for RGB pictures and 4 for CMYK
pictures.
bits is the number of bits for each color.
For some image types, the presence of channels and
bits values can be a bit
confusing. As an example, GIF always uses 3 channels
per pixel, but the number of bits per pixel cannot be calculated for an
animated GIF with a global color table.
On failure, FALSE is returned.
If accessing the filename image is impossible
getimagesize() will generate an error of level
E_WARNING. On read error,
getimagesize() will generate an error of level
E_NOTICE.
| Version | Description |
|---|---|
| 7.1.0 | Added WebP support. |
| 5.3.0 | Added icon support. |
| 5.2.3 |
Read errors generated by this function downgraded to
E_NOTICE from E_WARNING.
|
Example #2 getimagesize() example
<?php
list($width, $height, $type, $attr) = getimagesize("img/flag.jpg");
echo "<img src=\"img/flag.jpg\" $attr alt=\"getimagesize() example\" />";
?>
Example #3 getimagesize (URL)
<?php
$size = getimagesize("http://www.example.com/gifs/logo.gif");
// if the file name has space in it, encode it properly
$size = getimagesize("http://www.example.com/gifs/lo%20go.gif");
?>
Example #4 getimagesize() returning IPTC
<?php
$size = getimagesize("testimg.jpg", $info);
if (isset($info["APP13"])) {
$iptc = iptcparse($info["APP13"]);
var_dump($iptc);
}
?>
Note:
This function does not require the GD image library.
(PHP 5 >= 5.4.0, PHP 7)
getimagesizefromstring — Get the size of an image from a string
$imagedata
[, array &$imageinfo
] ) : arrayIdentical to getimagesize() except that getimagesizefromstring() accepts a string instead of a file name as the first parameter.
See the getimagesize() documentation for details on how this function works.
imagedataThe image data, as a string.
imageinfoSee getimagesize().
See getimagesize().
Example #1 getimagesizefromstring() example
<?php
$img = '/path/to/test.png';
// Open as a file
$size_info1 = getimagesize($img);
// Or open as a string
$data = file_get_contents($img);
$size_info2 = getimagesizefromstring($data);
?>
(PHP 5 >= 5.2.0, PHP 7)
image_type_to_extension — Get file extension for image type
$imagetype
[, bool $include_dot = TRUE
] ) : string
Returns the extension for the given IMAGETYPE_XXX
constant.
imagetype
One of the IMAGETYPE_XXX constant.
include_dot
Whether to prepend a dot to the extension or not. Default to TRUE.
A string with the extension corresponding to the given image type.
Example #1 image_type_to_extension() example
<?php
// Create image instance
$im = imagecreatetruecolor(100, 100);
// Save image
imagepng($im, './test' . image_type_to_extension(IMAGETYPE_PNG));
imagedestroy($im);
?>
Note:
This function does not require the GD image library.
(PHP 4 >= 4.3.0, PHP 5, PHP 7)
image_type_to_mime_type — Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype
$imagetype
) : stringThe image_type_to_mime_type() function will determine the Mime-Type for an IMAGETYPE constant.
imagetype
One of the IMAGETYPE_XXX constants.
The returned values are as follows
imagetype |
Returned value |
|---|---|
IMAGETYPE_GIF |
image/gif |
IMAGETYPE_JPEG |
image/jpeg |
IMAGETYPE_PNG |
image/png |
IMAGETYPE_SWF |
application/x-shockwave-flash |
IMAGETYPE_PSD |
image/psd |
IMAGETYPE_BMP |
image/bmp |
IMAGETYPE_TIFF_II (intel byte order) |
image/tiff |
IMAGETYPE_TIFF_MM (motorola byte order)
|
image/tiff |
IMAGETYPE_JPC |
application/octet-stream |
IMAGETYPE_JP2 |
image/jp2 |
IMAGETYPE_JPX |
application/octet-stream |
IMAGETYPE_JB2 |
application/octet-stream |
IMAGETYPE_SWC |
application/x-shockwave-flash |
IMAGETYPE_IFF |
image/iff |
IMAGETYPE_WBMP |
image/vnd.wap.wbmp |
IMAGETYPE_XBM |
image/xbm |
IMAGETYPE_ICO |
image/vnd.microsoft.icon |
IMAGETYPE_WEBP |
image/webp |
Example #1 image_type_to_mime_type() example
<?php
header("Content-type: " . image_type_to_mime_type(IMAGETYPE_PNG));
?>
Note:
This function does not require the GD image library.
(PHP 4 >= 4.0.5, PHP 5, PHP 7)
image2wbmp — Output image to browser or file
image2wbmp() is deprecated as of PHP 7.3.0, and will be removed in the next major version. Use imagewbmp() instead.
$image
[, string $filename
[, int $foreground
]] ) : bool
image2wbmp() outputs or save a WBMP
version of the given image.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
filenamePath to the saved file. If not given, the raw image stream will be output directly.
foregroundYou can set the foreground color with this parameter by setting an identifier obtained from imagecolorallocate(). The default foreground color is black.
Returns TRUE on success or FALSE on failure.
However, if libgd fails to output the image, this function returns TRUE.
Example #1 image2wbmp() example
<?php
$file = 'php.png';
$image = imagecreatefrompng($file);
header('Content-Type: ' . image_type_to_mime_type(IMAGETYPE_WBMP));
image2wbmp($image); // output the stream directly
imagedestroy($image);
?>
(PHP 5 >= 5.5.0, PHP 7)
imageaffine — Return an image containing the affine transformed src image, using an optional clipping area
$image
, array $affine
[, array $clip
] ) : resource
This function is currently not documented; only its argument list is available.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
affineArray with keys 0 to 5.
clipArray with keys "x", "y", "width" and "height".
Return affined image resource on success or FALSE on failure.
(PHP 5 >= 5.5.0, PHP 7)
imageaffinematrixconcat — Concatenate two affine transformation matrices
$m1
, array $m2
) : arrayReturns the concatenation of two affine transformation matrices, what is useful if multiple transformations should be applied to the same image in one go.
m1
An affine transformation matrix (an array with keys
0 to 5 and float values).
m2
An affine transformation matrix (an array with keys
0 to 5 and float values).
An affine transformation matrix (an array with keys
0 to 5 and float values)
or FALSE on failure.
Example #1 imageaffinematrixconcat() example
<?php
$m1 = imageaffinematrixget(IMG_AFFINE_TRANSLATE, array('x' = 2, 'y' => 3));
$m2 = imageaffinematrixget(IMG_AFFINE_SCALE, array('x' = 4, 'y' => 5));
$matrix = imageaffinematrixconcat($m1, $m2);
print_r($matrix);
?>
The above example will output:
Array
(
[0] => 4
[1] => 0
[2] => 0
[3] => 5
[4] => 8
[5] => 15
)
(PHP 5 >= 5.5.0, PHP 7)
imageaffinematrixget — Get an affine transformation matrix
Returns an affine transformation matrix.
type
One of the IMG_AFFINE_* constants.
options
If type is IMG_AFFINE_TRANSLATE
or IMG_AFFINE_SCALE,
options has to be an array with keys x
and y, both having float values.
If type is IMG_AFFINE_ROTATE,
IMG_AFFINE_SHEAR_HORIZONTAL or IMG_AFFINE_SHEAR_VERTICAL,
options has to be a float specifying the angle.
An affine transformation matrix (an array with keys
0 to 5 and float values)
or FALSE on failure.
Example #1 imageaffinematrixget() example
<?php
$matrix = imageaffinematrixget(IMG_AFFINE_TRANSLATE, array('x' = 2, 'y' => 3));
print_r($matrix);
?>
The above example will output:
Array
(
[0] => 1
[1] => 0
[2] => 0
[3] => 1
[4] => 2
[5] => 3
)
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
imagealphablending — Set the blending mode for an image
$image
, bool $blendmode
) : boolimagealphablending() allows for two different modes of drawing on truecolor images. In blending mode, the alpha channel component of the color supplied to all drawing function, such as imagesetpixel() determines how much of the underlying color should be allowed to shine through. As a result, gd automatically blends the existing color at that point with the drawing color, and stores the result in the image. The resulting pixel is opaque. In non-blending mode, the drawing color is copied literally with its alpha channel information, replacing the destination pixel. Blending mode is not available when drawing on palette images.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
blendmode
Whether to enable the blending mode or not. On true color images
the default value is TRUE otherwise the default value is FALSE
Returns TRUE on success or FALSE on failure.
Example #1 imagealphablending() usage example
<?php
// Create image
$im = imagecreatetruecolor(100, 100);
// Set alphablending to on
imagealphablending($im, true);
// Draw a square
imagefilledrectangle($im, 30, 30, 70, 70, imagecolorallocate($im, 255, 0, 0));
// Output
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
(PHP 4 >= 4.3.2, PHP 5, PHP 7)
imageantialias — Should antialias functions be used or not
$image
, bool $enabled
) : boolActivate the fast drawing antialiased methods for lines and wired polygons. It does not support alpha components. It works using a direct blend operation. It works only with truecolor images.
Thickness and styled are not supported.
Using antialiased primitives with transparent background color can end with some unexpected results. The blend method uses the background color as any other colors. The lack of alpha component support does not allow an alpha based antialiasing method.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
enabledWhether to enable antialiasing or not.
Returns TRUE on success or FALSE on failure.
| Version | Description |
|---|---|
| 7.2.0 | imageantialias() is now generally available. Formerly it was only available if PHP was compiled with the bundled version of the GD library. |
Example #1 A comparison of two lines, one with anti-aliasing switched on
<?php
// Setup an anti-aliased image and a normal image
$aa = imagecreatetruecolor(400, 100);
$normal = imagecreatetruecolor(200, 100);
// Switch antialiasing on for one image
imageantialias($aa, true);
// Allocate colors
$red = imagecolorallocate($normal, 255, 0, 0);
$red_aa = imagecolorallocate($aa, 255, 0, 0);
// Draw two lines, one with AA enabled
imageline($normal, 0, 0, 200, 100, $red);
imageline($aa, 0, 0, 200, 100, $red_aa);
// Merge the two images side by side for output (AA: left, Normal: Right)
imagecopymerge($aa, $normal, 200, 0, 0, 0, 200, 100, 100);
// Output image
header('Content-type: image/png');
imagepng($aa);
imagedestroy($aa);
imagedestroy($normal);
?>
The above example will output something similar to:
(PHP 4, PHP 5, PHP 7)
imagearc — Draws an arc
$image
, int $cx
, int $cy
, int $width
, int $height
, int $start
, int $end
, int $color
) : boolimagearc() draws an arc of circle centered at the given coordinates.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
cxx-coordinate of the center.
cyy-coordinate of the center.
widthThe arc width.
heightThe arc height.
startThe arc start angle, in degrees.
endThe arc end angle, in degrees. 0° is located at the three-o'clock position, and the arc is drawn clockwise.
colorA color identifier created with imagecolorallocate().
Returns TRUE on success or FALSE on failure.
Example #1 Drawing a circle with imagearc()
<?php
// create a 200*200 image
$img = imagecreatetruecolor(200, 200);
// allocate some colors
$white = imagecolorallocate($img, 255, 255, 255);
$red = imagecolorallocate($img, 255, 0, 0);
$green = imagecolorallocate($img, 0, 255, 0);
$blue = imagecolorallocate($img, 0, 0, 255);
// draw the head
imagearc($img, 100, 100, 200, 200, 0, 360, $white);
// mouth
imagearc($img, 100, 100, 150, 150, 25, 155, $red);
// left and then the right eye
imagearc($img, 60, 75, 50, 50, 0, 360, $green);
imagearc($img, 140, 75, 50, 50, 0, 360, $blue);
// output image in the browser
header("Content-type: image/png");
imagepng($img);
// free memory
imagedestroy($img);
?>
The above example will output something similar to:
(PHP 7 >= 7.2.0)
imagebmp — Output a BMP image to browser or file
Outputs or saves a BMP version of the given image.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
toThe path or an open stream resource (which is automatically being closed after this function returns) to save the file to. If not set or NULL, the raw image stream will be outputted directly.
Note:
NULLis invalid if thecompressedarguments is not used.
compressedWhether the BMP should be compressed with run-length encoding (RLE), or not.
Returns TRUE on success or FALSE on failure.
However, if libgd fails to output the image, this function returns TRUE.
Example #1 Saving a BMP file
<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'BMP with PHP', $text_color);
// Save the image
imagebmp($im, 'php.bmp');
// Free up memory
imagedestroy($im);
?>
(PHP 4, PHP 5, PHP 7)
imagechar — Draw a character horizontally
$image
, int $font
, int $x
, int $y
, string $c
, int $color
) : bool
imagechar() draws the first character of
c in the image identified by
image with its upper-left at
x,y (top left is 0,
0) with the color color.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
fontCan be 1, 2, 3, 4, 5 for built-in fonts in latin2 encoding (where higher numbers corresponding to larger fonts) or any of your own font identifiers registered with imageloadfont().
xx-coordinate of the start.
yy-coordinate of the start.
cThe character to draw.
colorA color identifier created with imagecolorallocate().
Returns TRUE on success or FALSE on failure.
Example #1 imagechar() example
<?php
$im = imagecreate(100, 100);
$string = 'PHP';
$bg = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
// prints a black "P" in the top left corner
imagechar($im, 1, 0, 0, $string, $black);
header('Content-type: image/png');
imagepng($im);
?>
The above example will output something similar to:
(PHP 4, PHP 5, PHP 7)
imagecharup — Draw a character vertically
$image
, int $font
, int $x
, int $y
, string $c
, int $color
) : bool
Draws the character c vertically at the specified
coordinate on the given image.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
fontCan be 1, 2, 3, 4, 5 for built-in fonts in latin2 encoding (where higher numbers corresponding to larger fonts) or any of your own font identifiers registered with imageloadfont().
xx-coordinate of the start.
yy-coordinate of the start.
cThe character to draw.
colorA color identifier created with imagecolorallocate().
Returns TRUE on success or FALSE on failure.
Example #1 imagecharup() example
<?php
$im = imagecreate(100, 100);
$string = 'Note that the first letter is a N';
$bg = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
// prints a black "Z" on a white background
imagecharup($im, 3, 10, 10, $string, $black);
header('Content-type: image/png');
imagepng($im);
?>
The above example will output something similar to:
(PHP 4, PHP 5, PHP 7)
imagecolorallocate — Allocate a color for an image
$image
, int $red
, int $green
, int $blue
) : intReturns a color identifier representing the color composed of the given RGB components.
imagecolorallocate() must be called
to create each color that is to be used in the image represented
by image.
Note:
The first call to imagecolorallocate() fills the background color in palette-based images - images created using imagecreate().
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
redValue of red component.
greenValue of green component.
blueValue of blue component.
A color identifier or FALSE if the allocation failed.
This function may
return Boolean FALSE, but may also return a non-Boolean value which
evaluates to FALSE. Please read the section on Booleans for more
information. Use the ===
operator for testing the return value of this
function.
| Version | Description |
|---|---|
| 5.1.3 |
Returns FALSE if the allocation failed. Previously
-1 was returned.
|
Example #1 imagecolorallocate() example
<?php
$im = imagecreate(100, 100);
// sets background to red
$background = imagecolorallocate($im, 255, 0, 0);
// sets some colors
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
// hexadecimal way
$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
$black = imagecolorallocate($im, 0x00, 0x00, 0x00);
?>
(PHP 4 >= 4.3.2, PHP 5, PHP 7)
imagecolorallocatealpha — Allocate a color for an image
$image
, int $red
, int $green
, int $blue
, int $alpha
) : int
imagecolorallocatealpha() behaves identically to
imagecolorallocate() with the addition of the transparency
parameter alpha.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
redValue of red component.
greenValue of green component.
blueValue of blue component.
alpha
A value between 0 and 127.
0 indicates completely opaque while
127 indicates completely transparent.
red, green
and blue parameters are integers
between 0 and 255 or hexadecimals between 0x00 and 0xFF.
A color identifier or FALSE if the allocation failed.
This function may
return Boolean FALSE, but may also return a non-Boolean value which
evaluates to FALSE. Please read the section on Booleans for more
information. Use the ===
operator for testing the return value of this
function.
| Version | Description |
|---|---|
| 5.1.3 |
Returns FALSE if the allocation failed. Previously
-1 was returned.
|
Example #1 Example of using imagecolorallocatealpha()
<?php
$size = 300;
$image=imagecreatetruecolor($size, $size);
// something to get a white background with black border
$back = imagecolorallocate($image, 255, 255, 255);
$border = imagecolorallocate($image, 0, 0, 0);
imagefilledrectangle($image, 0, 0, $size - 1, $size - 1, $back);
imagerectangle($image, 0, 0, $size - 1, $size - 1, $border);
$yellow_x = 100;
$yellow_y = 75;
$red_x = 120;
$red_y = 165;
$blue_x = 187;
$blue_y = 125;
$radius = 150;
// allocate colors with alpha values
$yellow = imagecolorallocatealpha($image, 255, 255, 0, 75);
$red = imagecolorallocatealpha($image, 255, 0, 0, 75);
$blue = imagecolorallocatealpha($image, 0, 0, 255, 75);
// drawing 3 overlapped circle
imagefilledellipse($image, $yellow_x, $yellow_y, $radius, $radius, $yellow);
imagefilledellipse($image, $red_x, $red_y, $radius, $radius, $red);
imagefilledellipse($image, $blue_x, $blue_y, $radius, $radius, $blue);
// don't forget to output a correct header!
header('Content-Type: image/png');
// and finally, output the result
imagepng($image);
imagedestroy($image);
?>
The above example will output something similar to:
Example #2 Convert typical alpha values for use with imagecolorallocatealpha()
Usually alpha values of 0 designate fully transparent pixels,
and the alpha channel has 8 bits. To convert such alpha values to be compatible
with imagecolorallocatealpha(), some simple arithmetic is
sufficient:
<?php
$alpha8 = 0; // fully transparent
var_dump(127 - ($alpha8 >> 1));
$alpha8 = 255; // fully opaque
var_dump(127 - ($alpha8 >> 1));
?>
The above example will output:
int(127) int(0)
(PHP 4, PHP 5, PHP 7)
imagecolorat — Get the index of the color of a pixel
$image
, int $x
, int $y
) : int
Returns the index of the color of the pixel at the
specified location in the image specified by image.
If the image is a truecolor image, this function returns the RGB value of that pixel as integer. Use bitshifting and masking to access the distinct red, green and blue component values:
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
xx-coordinate of the point.
yy-coordinate of the point.
Returns the index of the color or FALSE on failure.
This function may
return Boolean FALSE, but may also return a non-Boolean value which
evaluates to FALSE. Please read the section on Booleans for more
information. Use the ===
operator for testing the return value of this
function.
Example #1 Access distinct RGB values
<?php
$im = imagecreatefrompng("php.png");
$rgb = imagecolorat($im, 10, 15);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
var_dump($r, $g, $b);
?>
The above example will output something similar to:
int(119) int(123) int(180)
Example #2 Human-readable RGB values using imagecolorsforindex()
<?php
$im = imagecreatefrompng("php.png");
$rgb = imagecolorat($im, 10, 15);
$colors = imagecolorsforindex($im, $rgb);
var_dump($colors);
?>
The above example will output something similar to:
array(4) {
["red"]=>
int(119)
["green"]=>
int(123)
["blue"]=>
int(180)
["alpha"]=>
int(127)
}
(PHP 4, PHP 5, PHP 7)
imagecolorclosest — Get the index of the closest color to the specified color
$image
, int $red
, int $green
, int $blue
) : intReturns the index of the color in the palette of the image which is "closest" to the specified RGB value.
The "distance" between the desired color and each color in the palette is calculated as if the RGB values represented points in three-dimensional space.
If you created the image from a file, only colors used in the image are resolved. Colors present only in the palette are not resolved.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
redValue of red component.
greenValue of green component.
blueValue of blue component.
Returns the index of the closest color, in the palette of the image, to the specified one
Example #1 Search for a set of colors in an image
<?php
// Start with an image and convert it to a palette-based image
$im = imagecreatefrompng('figures/imagecolorclosest.png');
imagetruecolortopalette($im, false, 255);
// Search colors (RGB)
$colors = array(
array(254, 145, 154),
array(153, 145, 188),
array(153, 90, 145),
array(255, 137, 92)
);
// Loop through each search and find the closest color in the palette.
// Return the search number, the search RGB and the converted RGB match
foreach($colors as $id => $rgb)
{
$result = imagecolorclosest($im, $rgb[0], $rgb[1], $rgb[2]);
$result = imagecolorsforindex($im, $result);
$result = "({$result['red']}, {$result['green']}, {$result['blue']})";
echo "#$id: Search ($rgb[0], $rgb[1], $rgb[2]); Closest match: $result.\n";
}
imagedestroy($im);
?>
The above example will output something similar to:
#0: Search (254, 145, 154); Closest match: (252, 150, 148). #1: Search (153, 145, 188); Closest match: (148, 150, 196). #2: Search (153, 90, 145); Closest match: (148, 90, 156). #3: Search (255, 137, 92); Closest match: (252, 150, 92).
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
imagecolorclosestalpha — Get the index of the closest color to the specified color + alpha
$image
, int $red
, int $green
, int $blue
, int $alpha
) : int
Returns the index of the color in the palette of the image which
is "closest" to the specified RGB value and
alpha level.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
redValue of red component.
greenValue of green component.
blueValue of blue component.
alpha
A value between 0 and 127.
0 indicates completely opaque while
127 indicates completely transparent.
Returns the index of the closest color in the palette.
Example #1 Search for a set of colors in an image
<?php
// Start with an image and convert it to a palette-based image
$im = imagecreatefrompng('figures/imagecolorclosest.png');
imagetruecolortopalette($im, false, 255);
// Search colors (RGB)
$colors = array(
array(254, 145, 154, 50),
array(153, 145, 188, 127),
array(153, 90, 145, 0),
array(255, 137, 92, 84)
);
// Loop through each search and find the closest color in the palette.
// Return the search number, the search RGB and the converted RGB match
foreach($colors as $id => $rgb)
{
$result = imagecolorclosestalpha($im, $rgb[0], $rgb[1], $rgb[2], $rgb[3]);
$result = imagecolorsforindex($im, $result);
$result = "({$result['red']}, {$result['green']}, {$result['blue']}, {$result['alpha']})";
echo "#$id: Search ($rgb[0], $rgb[1], $rgb[2], $rgb[3]); Closest match: $result.\n";
}
imagedestroy($im);
?>
The above example will output something similar to:
#0: Search (254, 145, 154, 50); Closest match: (252, 150, 148, 0). #1: Search (153, 145, 188, 127); Closest match: (148, 150, 196, 0). #2: Search (153, 90, 145, 0); Closest match: (148, 90, 156, 0). #3: Search (255, 137, 92, 84); Closest match: (252, 150, 92, 0).
(PHP 4 >= 4.0.1, PHP 5, PHP 7)
imagecolorclosesthwb — Get the index of the color which has the hue, white and blackness
$image
, int $red
, int $green
, int $blue
) : intGet the index of the color which has the hue, white and blackness nearest the given color.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
redValue of red component.
greenValue of green component.
blueValue of blue component.
Returns an integer with the index of the color which has the hue, white and blackness nearest the given color.
| Version | Description |
|---|---|
| 5.3.0 | This function is now available on Windows |
Example #1 Example of using imagecolorclosesthwb()
<?php
$im = imagecreatefromgif('php.gif');
echo 'HWB: ' . imagecolorclosesthwb($im, 116, 115, 152);
imagedestroy($im);
?>
The above example will output something similar to:
HWB: 33
(PHP 4, PHP 5, PHP 7)
imagecolordeallocate — De-allocate a color for an image
$image
, int $color
) : boolDe-allocates a color previously allocated with imagecolorallocate() or imagecolorallocatealpha().
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
colorThe color identifier.
Returns TRUE on success or FALSE on failure.
Example #1 Using imagecolordeallocate()
<?php
$white = imagecolorallocate($im, 255, 255, 255);
imagecolordeallocate($im, $white);
?>
(PHP 4, PHP 5, PHP 7)
imagecolorexact — Get the index of the specified color
$image
, int $red
, int $green
, int $blue
) : intReturns the index of the specified color in the palette of the image.
If you created the image from a file, only colors used in the image are resolved. Colors present only in the palette are not resolved.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
redValue of red component.
greenValue of green component.
blueValue of blue component.
Returns the index of the specified color in the palette, or -1 if the color does not exist.
Example #1 Get colors from the GD logo
<?php
// Setup an image
$im = imagecreatefrompng('./gdlogo.png');
$colors = Array();
$colors[] = imagecolorexact($im, 255, 0, 0);
$colors[] = imagecolorexact($im, 0, 0, 0);
$colors[] = imagecolorexact($im, 255, 255, 255);
$colors[] = imagecolorexact($im, 100, 255, 52);
print_r($colors);
// Free from memory
imagedestroy($im);
?>
The above example will output something similar to:
Array
(
[0] => 16711680
[1] => 0
[2] => 16777215
[3] => 6618932
)
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
imagecolorexactalpha — Get the index of the specified color + alpha
$image
, int $red
, int $green
, int $blue
, int $alpha
) : intReturns the index of the specified color+alpha in the palette of the image.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
redValue of red component.
greenValue of green component.
blueValue of blue component.
alpha
A value between 0 and 127.
0 indicates completely opaque while
127 indicates completely transparent.
Returns the index of the specified color+alpha in the palette of the image, or -1 if the color does not exist in the image's palette.
Example #1 Get colors from the GD logo
<?php
// Setup an image
$im = imagecreatefrompng('./gdlogo.png');
$colors = Array();
$colors[] = imagecolorexactalpha($im, 255, 0, 0, 0);
$colors[] = imagecolorexactalpha($im, 0, 0, 0, 127);
$colors[] = imagecolorexactalpha($im, 255, 255, 255, 55);
$colors[] = imagecolorexactalpha($im, 100, 255, 52, 20);
print_r($colors);
// Free from memory
imagedestroy($im);
?>
The above example will output something similar to:
Array
(
[0] => 16711680
[1] => 2130706432
[2] => 939524095
[3] => 342163252
)
(PHP 4 >= 4.3.0, PHP 5, PHP 7)
imagecolormatch — Makes the colors of the palette version of an image more closely match the true color version
$image1
, resource $image2
) : boolMakes the colors of the palette version of an image more closely match the true color version.
image1A truecolor image resource.
image2
A palette image resource pointing to an image that has the same
size as image1.
Returns TRUE on success or FALSE on failure.
Example #1 imagecolormatch() example
<?php
// Setup the true color and palette images
$im1 = imagecreatefrompng('./gdlogo.png');
$im2 = imagecreate(imagesx($im1), imagesy($im1));
// Add some colors to $im2
$colors = Array();
$colors[] = imagecolorallocate($im2, 255, 36, 74);
$colors[] = imagecolorallocate($im2, 40, 0, 240);
$colors[] = imagecolorallocate($im2, 82, 100, 255);
$colors[] = imagecolorallocate($im2, 84, 63, 44);
// Match these colors with the true color image
imagecolormatch($im1, $im2);
// Free from memory
imagedestroy($im1);
imagedestroy($im2);
?>
(PHP 4, PHP 5, PHP 7)
imagecolorresolve — Get the index of the specified color or its closest possible alternative
$image
, int $red
, int $green
, int $blue
) : intThis function is guaranteed to return a color index for a requested color, either the exact color or the closest possible alternative.
If you created the image from a file, only colors used in the image are resolved. Colors present only in the palette are not resolved.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
redValue of red component.
greenValue of green component.
blueValue of blue component.
Returns a color index.
Example #1 Using imagecoloresolve() to get colors from an image
<?php
// Load an image
$im = imagecreatefromgif('phplogo.gif');
// Get closest colors from the image
$colors = array();
$colors[] = imagecolorresolve($im, 255, 255, 255);
$colors[] = imagecolorresolve($im, 0, 0, 200);
// Output
print_r($colors);
imagedestroy($im);
?>
The above example will output something similar to:
Array
(
[0] => 89
[1] => 85
)
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
imagecolorresolvealpha — Get the index of the specified color + alpha or its closest possible alternative
$image
, int $red
, int $green
, int $blue
, int $alpha
) : intThis function is guaranteed to return a color index for a requested color, either the exact color or the closest possible alternative.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
redValue of red component.
greenValue of green component.
blueValue of blue component.
alpha
A value between 0 and 127.
0 indicates completely opaque while
127 indicates completely transparent.
Returns a color index.
Example #1 Using imagecoloresolvealpha() to get colors from an image
<?php
// Load an image
$im = imagecreatefromgif('phplogo.gif');
// Get closest colors from the image
$colors = array();
$colors[] = imagecolorresolvealpha($im, 255, 255, 255, 0);
$colors[] = imagecolorresolvealpha($im, 0, 0, 200, 127);
// Output
print_r($colors);
imagedestroy($im);
?>
The above example will output something similar to:
Array
(
[0] => 89
[1] => 85
)
(PHP 4, PHP 5, PHP 7)
imagecolorset — Set the color for the specified palette index
$image
, int $index
, int $red
, int $green
, int $blue
[, int $alpha = 0
] ) : voidThis sets the specified index in the palette to the specified color. This is useful for creating flood-fill-like effects in palleted images without the overhead of performing the actual flood-fill.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
indexAn index in the palette.
redValue of red component.
greenValue of green component.
blueValue of blue component.
alphaValue of alpha component.
No value is returned.
| Version | Description |
|---|---|
| 5.4.0 |
The alpha parameter was added.
|
Example #1 imagecolorset() example
<?php
// Create a 300x100 image
$im = imagecreate(300, 100);
// Set the background to be red
imagecolorallocate($im, 255, 0, 0);
// Get the color index for the background
$bg = imagecolorat($im, 0, 0);
// Set the backgrund to be blue
imagecolorset($im, $bg, 0, 0, 255);
// Output the image to the browser
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
(PHP 4, PHP 5, PHP 7)
imagecolorsforindex — Get the colors for an index
$image
, int $index
) : arrayGets the color for a specified index.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
indexThe color index.
Returns an associative array with red, green, blue and alpha keys that contain the appropriate values for the specified color index.
Example #1 imagecolorsforindex() example
<?php
// open an image
$im = imagecreatefrompng('nexen.png');
// get a color
$start_x = 40;
$start_y = 50;
$color_index = imagecolorat($im, $start_x, $start_y);
// make it human readable
$color_tran = imagecolorsforindex($im, $color_index);
// what is it ?
print_r($color_tran);
?>
The above example will output something similar to:
Array
(
[red] => 226
[green] => 222
[blue] => 252
[alpha] => 0
)
(PHP 4, PHP 5, PHP 7)
imagecolorstotal — Find out the number of colors in an image's palette
$image
) : intReturns the number of colors in an image palette.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
Returns the number of colors in the specified image's palette or 0 for truecolor images.
Example #1 Getting total number of colors in an image using imagecolorstotal()
<?php
// Create image instance
$im = imagecreatefromgif('php.gif');
echo 'Total colors in image: ' . imagecolorstotal($im);
// Free image
imagedestroy($im);
?>
The above example will output something similar to:
Total colors in image: 128
(PHP 4, PHP 5, PHP 7)
imagecolortransparent — Define a color as transparent
$image
) : int$image
, int $color
) : int
Gets or sets the transparent color in the given image.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
colorA color identifier created with imagecolorallocate().
The identifier of the new (or current, if none is specified)
transparent color is returned. If color
is not specified, and the image has no transparent color, the
returned identifier will be -1.
Example #1 imagecolortransparent() example
<?php
// Create a 55x30 image
$im = imagecreatetruecolor(55, 30);
$red = imagecolorallocate($im, 255, 0, 0);
$black = imagecolorallocate($im, 0, 0, 0);
// Make the background transparent
imagecolortransparent($im, $black);
// Draw a red rectangle
imagefilledrectangle($im, 4, 4, 50, 25, $red);
// Save the image
imagepng($im, './imagecolortransparent.png');
imagedestroy($im);
?>
The above example will output something similar to:
Note:
Transparency is copied only with imagecopymerge() and true color images, not with imagecopy() or pallete images.
Note:
The transparent color is a property of the image, transparency is not a property of the color. Once you have set a color to be the transparent color, any regions of the image in that color that were drawn previously will be transparent.
(PHP 5 >= 5.1.0, PHP 7)
imageconvolution — Apply a 3x3 convolution matrix, using coefficient and offset
$image
, array $matrix
, float $div
, float $offset
) : boolApplies a convolution matrix on the image, using the given coefficient and offset.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
matrixA 3x3 matrix: an array of three arrays of three floats.
divThe divisor of the result of the convolution, used for normalization.
offsetColor offset.
Returns TRUE on success or FALSE on failure.
Example #1 Embossing the PHP.net logo
<?php
$image = imagecreatefromgif('http://www.php.net/images/php.gif');
$emboss = array(array(2, 0, 0), array(0, -1, 0), array(0, 0, -1));
imageconvolution($image, $emboss, 1, 127);
header('Content-Type: image/png');
imagepng($image, null, 9);
?>
The above example will output:
Example #2 Gaussian blur
<?php
$image = imagecreatetruecolor(180,40);
// Writes the text and apply a gaussian blur on the image
imagestring($image, 5, 10, 8, 'Gaussian Blur Text', 0x00ff00);
$gaussian = array(array(1.0, 2.0, 1.0), array(2.0, 4.0, 2.0), array(1.0, 2.0, 1.0));
imageconvolution($image, $gaussian, 16, 0);
// Rewrites the text for comparison
imagestring($image, 5, 10, 18, 'Gaussian Blur Text', 0x00ff00);
header('Content-Type: image/png');
imagepng($image, null, 9);
?>
The above example will output:
This function requires GD 2.1.0 or higher.
(PHP 4, PHP 5, PHP 7)
imagecopy — Copy part of an image
$dst_im
, resource $src_im
, int $dst_x
, int $dst_y
, int $src_x
, int $src_y
, int $src_w
, int $src_h
) : bool
Copy a part of src_im onto
dst_im starting at the x,y coordinates
src_x, src_y with
a width of src_w and a height of
src_h. The portion defined will be copied
onto the x,y coordinates, dst_x and
dst_y.
dst_imDestination image resource.
src_imSource image resource.
dst_xx-coordinate of destination point.
dst_yy-coordinate of destination point.
src_xx-coordinate of source point.
src_yy-coordinate of source point.
src_wSource width.
src_hSource height.
Returns TRUE on success or FALSE on failure.
Example #1 Cropping the PHP.net logo
<?php
// Create image instances
$src = imagecreatefromgif('php.gif');
$dest = imagecreatetruecolor(80, 40);
// Copy
imagecopy($dest, $src, 0, 0, 20, 13, 80, 40);
// Output and free from memory
header('Content-Type: image/gif');
imagegif($dest);
imagedestroy($dest);
imagedestroy($src);
?>
The above example will output something similar to:
(PHP 4 >= 4.0.1, PHP 5, PHP 7)
imagecopymerge — Copy and merge part of an image
$dst_im
, resource $src_im
, int $dst_x
, int $dst_y
, int $src_x
, int $src_y
, int $src_w
, int $src_h
, int $pct
) : bool
Copy a part of src_im onto
dst_im starting at the x,y coordinates
src_x, src_y with
a width of src_w and a height of
src_h. The portion defined will be copied
onto the x,y coordinates, dst_x and
dst_y.
dst_imDestination image resource.
src_imSource image resource.
dst_xx-coordinate of destination point.
dst_yy-coordinate of destination point.
src_xx-coordinate of source point.
src_yy-coordinate of source point.
src_wSource width.
src_hSource height.
pct
The two images will be merged according to pct
which can range from 0 to 100. When pct = 0,
no action is taken, when 100 this function behaves identically
to imagecopy() for pallete images, except for
ignoring alpha components, while it implements alpha transparency
for true colour images.
Returns TRUE on success or FALSE on failure.
Example #1 Merging two copies of the PHP.net logo with 75% transparency
<?php
// Create image instances
$dest = imagecreatefromgif('php.gif');
$src = imagecreatefromgif('php.gif');
// Copy and merge
imagecopymerge($dest, $src, 10, 10, 0, 0, 100, 47, 75);
// Output and free from memory
header('Content-Type: image/gif');
imagegif($dest);
imagedestroy($dest);
imagedestroy($src);
?>
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
imagecopymergegray — Copy and merge part of an image with gray scale
$dst_im
, resource $src_im
, int $dst_x
, int $dst_y
, int $src_x
, int $src_y
, int $src_w
, int $src_h
, int $pct
) : bool
imagecopymergegray() copy a part of src_im onto
dst_im starting at the x,y coordinates
src_x, src_y with
a width of src_w and a height of
src_h. The portion defined will be copied
onto the x,y coordinates, dst_x and
dst_y.
This function is identical to imagecopymerge() except that when merging it preserves the hue of the source by converting the destination pixels to gray scale before the copy operation.
dst_imDestination image resource.
src_imSource image resource.
dst_xx-coordinate of destination point.
dst_yy-coordinate of destination point.
src_xx-coordinate of source point.
src_yy-coordinate of source point.
src_wSource width.
src_hSource height.
pct
The src_im will be changed to grayscale according
to pct where 0 is fully grayscale and 100 is
unchanged. When pct = 100 this function behaves
identically to imagecopy() for pallete images, except for
ignoring alpha components, while
it implements alpha transparency for true colour images.
Returns TRUE on success or FALSE on failure.
Example #1 imagecopymergegray() usage
<?php
// Create image instances
$dest = imagecreatefromgif('php.gif');
$src = imagecreatefromgif('php.gif');
// Copy and merge - Gray = 20%
imagecopymergegray($dest, $src, 10, 10, 0, 0, 100, 47, 20);
// Output and free from memory
header('Content-Type: image/gif');
imagegif($dest);
imagedestroy($dest);
imagedestroy($src);
?>
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
imagecopyresampled — Copy and resize part of an image with resampling
$dst_image
, resource $src_image
, int $dst_x
, int $dst_y
, int $src_x
, int $src_y
, int $dst_w
, int $dst_h
, int $src_w
, int $src_h
) : boolimagecopyresampled() copies a rectangular portion of one image to another image, smoothly interpolating pixel values so that, in particular, reducing the size of an image still retains a great deal of clarity.
In other words, imagecopyresampled() will take a
rectangular area from src_image of width
src_w and height src_h at
position (src_x,src_y)
and place it in a rectangular area of dst_image
of width dst_w and height dst_h
at position (dst_x,dst_y).
If the source and destination coordinates and width and heights
differ, appropriate stretching or shrinking of the image fragment
will be performed. The coordinates refer to the upper left
corner. This function can be used to copy regions within the
same image (if dst_image is the same as
src_image) but if the regions overlap the
results will be unpredictable.
dst_imageDestination image resource.
src_imageSource image resource.
dst_xx-coordinate of destination point.
dst_yy-coordinate of destination point.
src_xx-coordinate of source point.
src_yy-coordinate of source point.
dst_wDestination width.
dst_hDestination height.
src_wSource width.
src_hSource height.
Returns TRUE on success or FALSE on failure.
Example #1 Simple example
This example will resample an image to half its original size.
<?php
// The file
$filename = 'test.jpg';
$percent = 0.5;
// Content type
header('Content-Type: image/jpeg');
// Get new dimensions
list($width, $height) = getimagesize($filename);
$new_width = $width * $percent;
$new_height = $height * $percent;
// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Output
imagejpeg($image_p, null, 100);
?>
The above example will output something similar to:
Example #2 Resampling an image proportionally
This example will display an image with the maximum width, or height, of 200 pixels.
<?php
// The file
$filename = 'test.jpg';
// Set a maximum height and width
$width = 200;
$height = 200;
// Content type
header('Content-Type: image/jpeg');
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
imagejpeg($image_p, null, 100);
?>
The above example will output something similar to:
Note:
There is a problem due to palette image limitations (255+1 colors). Resampling or filtering an image commonly needs more colors than 255, a kind of approximation is used to calculate the new resampled pixel and its color. With a palette image we try to allocate a new color, if that failed, we choose the closest (in theory) computed color. This is not always the closest visual color. That may produce a weird result, like blank (or visually blank) images. To skip this problem, please use a truecolor image as a destination image, such as one created by imagecreatetruecolor().
imagecopyresized() - Copy and resize part of an image imagescale() - Scale an image using the given new width and height
(PHP 4, PHP 5, PHP 7)
imagecopyresized — Copy and resize part of an image
$dst_image
, resource $src_image
, int $dst_x
, int $dst_y
, int $src_x
, int $src_y
, int $dst_w
, int $dst_h
, int $src_w
, int $src_h
) : bool
imagecopyresized() copies a rectangular
portion of one image to another image.
dst_image is the destination image,
src_image is the source image identifier.
In other words, imagecopyresized() will take a
rectangular area from src_image of width
src_w and height src_h at
position (src_x,src_y)
and place it in a rectangular area of dst_image
of width dst_w and height dst_h
at position (dst_x,dst_y).
If the source and destination coordinates and width and heights
differ, appropriate stretching or shrinking of the image fragment
will be performed. The coordinates refer to the upper left
corner. This function can be used to copy regions within the
same image (if dst_image is the same as
src_image) but if the regions overlap the
results will be unpredictable.
dst_imageDestination image resource.
src_imageSource image resource.
dst_xx-coordinate of destination point.
dst_yy-coordinate of destination point.
src_xx-coordinate of source point.
src_yy-coordinate of source point.
dst_wDestination width.
dst_hDestination height.
src_wSource width.
src_hSource height.
Returns TRUE on success or FALSE on failure.
Example #1 Resizing an image
This example will display the image at half size.
<?php
// File and new size
$filename = 'test.jpg';
$percent = 0.5;
// Content type
header('Content-Type: image/jpeg');
// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output
imagejpeg($thumb);
?>
The above example will output something similar to:
The image will be output at half size, though better quality could be obtained using imagecopyresampled().
Note:
There is a problem due to palette image limitations (255+1 colors). Resampling or filtering an image commonly needs more colors than 255, a kind of approximation is used to calculate the new resampled pixel and its color. With a palette image we try to allocate a new color, if that failed, we choose the closest (in theory) computed color. This is not always the closest visual color. That may produce a weird result, like blank (or visually blank) images. To skip this problem, please use a truecolor image as a destination image, such as one created by imagecreatetruecolor().
imagecopyresampled() - Copy and resize part of an image with resampling imagescale() - Scale an image using the given new width and height
(PHP 4, PHP 5, PHP 7)
imagecreate — Create a new palette based image
$width
, int $height
) : resourceimagecreate() returns an image identifier representing a blank image of specified size.
In general, we recommend the use of imagecreatetruecolor() instead of imagecreate() so that image processing occurs on the highest quality image possible. If you want to output a palette image, then imagetruecolortopalette() should be called immediately before saving the image with imagepng() or imagegif().
widthThe image width.
heightThe image height.
Returns an image resource identifier on success, FALSE on errors.
Example #1 Creating a new GD image stream and outputting an image.
<?php
header("Content-Type: image/png");
$im = @imagecreate(110, 20)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
?>
The above example will output something similar to:
(PHP 7 >= 7.2.0)
imagecreatefrombmp — Create a new image from file or URL
$filename
) : resourceimagecreatefrombmp() returns an image identifier representing the image obtained from the given filename.
A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.
filenamePath to the BMP image.
Returns an image resource identifier on success, FALSE on errors.
Example #1 Convert an BMP image to a PNG image using imagecreatefrombmp()
<?php
// Load the BMP file
$im = imagecreatefrombmp('./example.bmp');
// Convert it to a PNG file with default settings
imagepng($im, './example.png');
imagedestroy($im);
?>
(PHP 4 >= 4.0.7, PHP 5, PHP 7)
imagecreatefromgd2 — Create a new image from GD2 file or URL
$filename
) : resourceCreate a new image from GD2 file or URL.
A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.
filenamePath to the GD2 image.
Returns an image resource identifier on success, FALSE on errors.
Example #1 imagecreatefromgd2() example
<?php
// Load the gd2 image
$im = imagecreatefromgd2('./test.gd2');
// Apply an effect on the image, in this
// case negate the image if PHP 5+
if(function_exists('imagefilter'))
{
imagefilter($im, IMG_FILTER_NEGATE);
}
// Save the image
imagegd2($im, './test_updated.gd2');
imagedestroy($im);
?>
The GD and GD2 image formats are proprietary image formats of libgd. They have to be regarded obsolete, and should only be used for development and testing purposes.
(PHP 4 >= 4.0.7, PHP 5, PHP 7)
imagecreatefromgd2part — Create a new image from a given part of GD2 file or URL
$filename
, int $srcX
, int $srcY
, int $width
, int $height
) : resourceCreate a new image from a given part of GD2 file or URL.
A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.
filenamePath to the GD2 image.
srcXx-coordinate of source point.
srcYy-coordinate of source point.
widthSource width.
heightSource height.
Returns an image resource identifier on success, FALSE on errors.
Example #1 imagecreatefromgd2part() example
<?php
// For this example we need the image size before
$image = getimagesize('./test.gd2');
// Create the image instance now we got the image
// sizes
$im = imagecreatefromgd2part('./test.gd2', 4, 4, ($image[0] / 2) - 6, ($image[1] / 2) - 6);
// Do an image operation, in this case we emboss the
// image if PHP 5+
if(function_exists('imagefilter'))
{
imagefilter($im, IMG_FILTER_EMBOSS);
}
// Save optimized image
imagegd2($im, './test_emboss.gd2');
imagedestroy($im);
?>
The GD and GD2 image formats are proprietary image formats of libgd. They have to be regarded obsolete, and should only be used for development and testing purposes.
(PHP 4 >= 4.0.7, PHP 5, PHP 7)
imagecreatefromgd — Create a new image from GD file or URL
$filename
) : resourceCreate a new image from GD file or URL.
A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.
filenamePath to the GD file.
Returns an image resource identifier on success, FALSE on errors.
Example #1 imagecreatefromgd() example
<?php
// Load the gd image
$im = @imagecreatefromgd('./test.gd');
// Test if the image was loaded
if(!is_resource($im))
{
die('Unable to load gd image!');
}
// Do image operations here
// Save the image
imagegd($im, './test_updated.gd');
imagedestroy($im);
?>
The GD and GD2 image formats are proprietary image formats of libgd. They have to be regarded obsolete, and should only be used for development and testing purposes.
(PHP 4, PHP 5, PHP 7)
imagecreatefromgif — Create a new image from file or URL
$filename
) : resourceimagecreatefromgif() returns an image identifier representing the image obtained from the given filename.
When reading GIF files into memory, only the first frame is returned in the image resource pointer. The size of the image is not necessarily what is reported by getimagesize().
A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.
filenamePath to the GIF image.
Returns an image resource identifier on success, FALSE on errors.
Example #1 Example to handle an error during loading of a GIF
<?php
function LoadGif($imgname)
{
/* Attempt to open */
$im = @imagecreatefromgif($imgname);
/* See if it failed */
if(!$im)
{
/* Create a blank image */
$im = imagecreatetruecolor (150, 30);
$bgc = imagecolorallocate ($im, 255, 255, 255);
$tc = imagecolorallocate ($im, 0, 0, 0);
imagefilledrectangle ($im, 0, 0, 150, 30, $bgc);
/* Output an error message */
imagestring ($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
}
return $im;
}
header('Content-Type: image/gif');
$img = LoadGif('bogus.image');
imagegif($img);
imagedestroy($img);
?>
The above example will output something similar to:
Note:
GIF support was removed from the GD library in Version 1.6, and added back in Version 2.0.28. This function is not available between these versions.
(PHP 4, PHP 5, PHP 7)
imagecreatefromjpeg — Create a new image from file or URL
$filename
) : resourceimagecreatefromjpeg() returns an image identifier representing the image obtained from the given filename.
A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.
filenamePath to the JPEG image.
Returns an image resource identifier on success, FALSE on errors.
Example #1 Example to handle an error during loading of a JPEG
<?php
function LoadJpeg($imgname)
{
/* Attempt to open */
$im = @imagecreatefromjpeg($imgname);
/* See if it failed */
if(!$im)
{
/* Create a black image */
$im = imagecreatetruecolor(150, 30);
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/* Output an error message */
imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
}
return $im;
}
header('Content-Type: image/jpeg');
$img = LoadJpeg('bogus.image');
imagejpeg($img);
imagedestroy($img);
?>
The above example will output something similar to:
(PHP 4, PHP 5, PHP 7)
imagecreatefrompng — Create a new image from file or URL
$filename
) : resourceimagecreatefrompng() returns an image identifier representing the image obtained from the given filename.
A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.
filenamePath to the PNG image.
Returns an image resource identifier on success, FALSE on errors.
Example #1 Example to handle an error during loading of a PNG
<?php
function LoadPNG($imgname)
{
/* Attempt to open */
$im = @imagecreatefrompng($imgname);
/* See if it failed */
if(!$im)
{
/* Create a blank image */
$im = imagecreatetruecolor(150, 30);
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/* Output an error message */
imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
}
return $im;
}
header('Content-Type: image/png');
$img = LoadPNG('bogus.image');
imagepng($img);
imagedestroy($img);
?>
The above example will output something similar to:
(PHP 4 >= 4.0.4, PHP 5, PHP 7)
imagecreatefromstring — Create a new image from the image stream in the string
$image
) : resource
imagecreatefromstring() returns an image identifier
representing the image obtained from the given image.
These types will be automatically detected if your build of PHP supports
them: JPEG, PNG, GIF, BMP, WBMP, and GD2.
imageA string containing the image data.
An image resource will be returned on success. FALSE is returned if
the image type is unsupported, the data is not in a recognised format,
or the image is corrupt and cannot be loaded.
imagecreatefromstring() raises an E_WARNING level error, if the data is not in a recognized format.
Example #1 imagecreatefromstring() example
<?php
$data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'
. 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'
. 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'
. '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';
$data = base64_decode($data);
$im = imagecreatefromstring($data);
if ($im !== false) {
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
}
else {
echo 'An error occurred.';
}
?>
The above example will output something similar to:
(PHP 4 >= 4.0.1, PHP 5, PHP 7)
imagecreatefromwbmp — Create a new image from file or URL
$filename
) : resourceimagecreatefromwbmp() returns an image identifier representing the image obtained from the given filename.
Note: WBMP images are Wireless Bitmaps, not Windows Bitmaps. The latter can be loaded with imagecreatefrombmp().
A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.
filenamePath to the WBMP image.
Returns an image resource identifier on success, FALSE on errors.
Example #1 Example to handle an error during loading of a WBMP
<?php
function LoadWBMP($imgname)
{
/* Attempt to open */
$im = @imagecreatefromwbmp($imgname);
/* See if it failed */
if(!$im)
{
/* Create a blank image */
$im = imagecreatetruecolor(150, 30);
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/* Output an error message */
imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
}
return $im;
}
header('Content-Type: image/vnd.wap.wbmp');
$img = LoadWBMP('bogus.image');
imagewbmp($img);
imagedestroy($img);
?>
(PHP 5 >= 5.4.0, PHP 7)
imagecreatefromwebp — Create a new image from file or URL
$filename
) : resourceimagecreatefromwebp() returns an image identifier representing the image obtained from the given filename.
A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.
filenamePath to the WebP image.
Returns an image resource identifier on success, FALSE on errors.
Example #1 Convert an WebP image to a jpeg image using imagecreatefromwebp()
<?php
// Load the WebP file
$im = imagecreatefromwebp('./example.webp');
// Convert it to a jpeg file with 100% quality
imagejpeg($im, './example.jpeg', 100);
imagedestroy($im);
?>
(PHP 4 >= 4.0.1, PHP 5, PHP 7)
imagecreatefromxbm — Create a new image from file or URL
$filename
) : resourceimagecreatefromxbm() returns an image identifier representing the image obtained from the given filename.
A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.
filenamePath to the XBM image.
Returns an image resource identifier on success, FALSE on errors.
Example #1 Convert an XBM image to a png image using imagecreatefromxbm()
<?php
// Load the xbm file
$xbm = imagecreatefromxbm('./example.xbm');
// Convert it to a png file
imagepng($xbm, './example.png');
imagedestroy($xbm);
?>
(PHP 4 >= 4.0.1, PHP 5, PHP 7)
imagecreatefromxpm — Create a new image from file or URL
$filename
) : resourceimagecreatefromxpm() returns an image identifier representing the image obtained from the given filename.
A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.
filenamePath to the XPM image.
Returns an image resource identifier on success, FALSE on errors.
| Version | Description |
|---|---|
| 5.3.19 | imagecreatefromxpm() is available on Windows. |
Example #1 Creating an image instance using imagecreatefromxpm()
<?php
// Check for XPM support
if(!(imagetypes() & IMG_XPM))
{
die('Support for xpm was not found!');
}
// Create the image instance
$xpm = imagecreatefromxpm('./example.xpm');
// Do image operations here
// PHP has no support for writing xpm images
// so in this case we save the image as a
// jpeg file with 100% quality
imagejpeg($xpm, './example.jpg', 100);
imagedestroy($xpm);
?>
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
imagecreatetruecolor — Create a new true color image
$width
, int $height
) : resourceimagecreatetruecolor() returns an image identifier representing a black image of the specified size.
widthImage width.
heightImage height.
Returns an image resource identifier on success, FALSE on errors.
Example #1 Creating a new GD image stream and outputting an image.
<?php
header ('Content-Type: image/png');
$im = @imagecreatetruecolor(120, 20)
or die('Cannot Initialize new GD image stream');
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
imagepng($im);
imagedestroy($im);
?>
The above example will output something similar to:
(PHP 5 >= 5.5.0, PHP 7)
imagecrop — Crop an image to the given rectangle
$image
, array $rect
) : resource
Crops an image to the given rectangular area and returns the resulting image.
The given image is not modified.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
rect
The cropping rectangle as array with keys
x, y, width and
height.
Return cropped image resource on success or FALSE on failure.
Example #1 imagecrop() example
This example shows how to crop an image to a square area.
<?php
$im = imagecreatefrompng('example.png');
$size = min(imagesx($im), imagesy($im));
$im2 = imagecrop($im, ['x' => 0, 'y' => 0, 'width' => $size, 'height' => $size]);
if ($im2 !== FALSE) {
imagepng($im2, 'example-cropped.png');
imagedestroy($im2);
}
imagedestroy($im);
?>
(PHP 5 >= 5.5.0, PHP 7)
imagecropauto — Crop an image automatically using one of the available modes
$image
[, int $mode = IMG_CROP_DEFAULT
[, float $threshold = .5
[, int $color = -1
]]] ) : resource
Automatically crops an image according to the given
mode.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
modeOne of the following constants:
IMG_CROP_DEFAULTIMG_CROP_TRANSPARENT.
Before PHP 7.4.0, the bundled libgd fell back to IMG_CROP_SIDES,
if the image had no transparent color.
IMG_CROP_TRANSPARENTIMG_CROP_BLACKIMG_CROP_WHITEIMG_CROP_SIDESIMG_CROP_THRESHOLDthreshold and
color.
thresholdSpecifies the tolerance in percent to be used while comparing the image color and the color to crop. The method used to calculate the color difference is based on the color distance in the RGB(a) cube.
Used only in IMG_CROP_THRESHOLD mode.
Note: Before PHP 7.4.0, the bundled libgd used a somewhat different algorithm, so the same
thresholdyielded different results for system and bundled libgd.
colorEither an RGB color value or a palette index.
Used only in IMG_CROP_THRESHOLD mode.
Returns a cropped image resource on success or FALSE on failure.
If the complete image was cropped, imagecrop() returns FALSE.
| Version | Description |
|---|---|
| 7.4.0 |
The behavior of imagecropauto() in the bundled libgd has been synced with
that of system libgd: IMG_CROP_DEFAULT no longer falls
back to IMG_CROP_SIDES and threshold-cropping now uses
the same algorithm as system libgd.
|
| 7.4.0 |
The default value of mode has been changed to
IMG_CROP_AUTO. Formerly, the default value has been
-1 which corresponds to IMG_CROP_DEFAULT,
but passing -1 is now deprecated.
|
Example #1 Proper handling of auto-cropping
As noted in the return value section, imagecropauto()
returns FALSE if the whole image
was cropped. In this example we have an image resource
$im which should be automatically cropped only if there
is something to crop; otherwise we want to proceed with the original image.
<?php
$cropped = imagecropauto($im, IMG_CROP_DEFAULT);
if ($cropped !== false) { // in case a new image resource was returned
imagedestroy($im); // we destroy the original image
$im = $cropped; // and assign the cropped image to $im
}
?>
(PHP 4, PHP 5, PHP 7)
imagedashedline — Draw a dashed line
$image
, int $x1
, int $y1
, int $x2
, int $y2
, int $color
) : boolThis function is deprecated. Use combination of imagesetstyle() and imageline() instead.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
x1Upper left x coordinate.
y1Upper left y coordinate 0, 0 is the top left corner of the image.
x2Bottom right x coordinate.
y2Bottom right y coordinate.
colorThe fill color. A color identifier created with imagecolorallocate().
Returns TRUE on success or FALSE on failure.
Example #1 imagedashedline() example
<?php
// Create a 100x100 image
$im = imagecreatetruecolor(100, 100);
$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
// Draw a vertical dashed line
imagedashedline($im, 50, 25, 50, 75, $white);
// Save the image
imagepng($im, './dashedline.png');
imagedestroy($im);
?>
The above example will output something similar to:
Example #2 Alternative to imagedashedline()
<?php
// Create a 100x100 image
$im = imagecreatetruecolor(100, 100);
$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
// Define our style: First 4 pixels is white and the
// next 4 is transparent. This creates the dashed line effect
$style = Array(
$white,
$white,
$white,
$white,
IMG_COLOR_TRANSPARENT,
IMG_COLOR_TRANSPARENT,
IMG_COLOR_TRANSPARENT,
IMG_COLOR_TRANSPARENT
);
imagesetstyle($im, $style);
// Draw the dashed line
imageline($im, 50, 25, 50, 75, IMG_COLOR_STYLED);
// Save the image
imagepng($im, './imageline.png');
imagedestroy($im);
?>
(PHP 4, PHP 5, PHP 7)
imagedestroy — Destroy an image
$image
) : bool
imagedestroy() frees any memory associated
with image image.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
Returns TRUE on success or FALSE on failure.
Example #1 Using imagedestroy() example
<?php
// create a 100 x 100 image
$im = imagecreatetruecolor(100, 100);
// alter or save the image
// frees image from memory
imagedestroy($im);
?>
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
imageellipse — Draw an ellipse
$image
, int $cx
, int $cy
, int $width
, int $height
, int $color
) : boolDraws an ellipse centered at the specified coordinates.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
cxx-coordinate of the center.
cyy-coordinate of the center.
widthThe ellipse width.
heightThe ellipse height.
colorThe color of the ellipse. A color identifier created with imagecolorallocate().
Returns TRUE on success or FALSE on failure.
Example #1 imageellipse() example
<?php
// Create a blank image.
$image = imagecreatetruecolor(400, 300);
// Select the background color.
$bg = imagecolorallocate($image, 0, 0, 0);
// Fill the background with the color selected above.
imagefill($image, 0, 0, $bg);
// Choose a color for the ellipse.
$col_ellipse = imagecolorallocate($image, 255, 255, 255);
// Draw the ellipse.
imageellipse($image, 200, 150, 300, 200, $col_ellipse);
// Output the image.
header("Content-type: image/png");
imagepng($image);
?>
The above example will output something similar to:
Note:
imageellipse() ignores imagesetthickness().
(PHP 4, PHP 5, PHP 7)
imagefill — Flood fill
$image
, int $x
, int $y
, int $color
) : bool
Performs a flood fill starting at the given coordinate (top left is 0, 0)
with the given color in the
image.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
xx-coordinate of start point.
yy-coordinate of start point.
colorThe fill color. A color identifier created with imagecolorallocate().
Returns TRUE on success or FALSE on failure.
Example #1 imagefill() example
<?php
$im = imagecreatetruecolor(100, 100);
// sets background to red
$red = imagecolorallocate($im, 255, 0, 0);
imagefill($im, 0, 0, $red);
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
The above example will output something similar to:
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
imagefilledarc — Draw a partial arc and fill it
$image
, int $cx
, int $cy
, int $width
, int $height
, int $start
, int $end
, int $color
, int $style
) : bool
Draws a partial arc centered at the specified coordinate in the
given image.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
cxx-coordinate of the center.
cyy-coordinate of the center.
widthThe arc width.
heightThe arc height.
startThe arc start angle, in degrees.
endThe arc end angle, in degrees. 0° is located at the three-o'clock position, and the arc is drawn clockwise.
colorA color identifier created with imagecolorallocate().
styleA bitwise OR of the following possibilities:
IMG_ARC_PIEIMG_ARC_CHORDIMG_ARC_NOFILLIMG_ARC_EDGEDIMG_ARC_PIE and IMG_ARC_CHORD are
mutually exclusive; IMG_ARC_CHORD just
connects the starting and ending angles with a straight line, while
IMG_ARC_PIE produces a rounded edge.
IMG_ARC_NOFILL indicates that the arc
or chord should be outlined, not filled. IMG_ARC_EDGED,
used together with IMG_ARC_NOFILL, indicates that the
beginning and ending angles should be connected to the center - this is a
good way to outline (rather than fill) a 'pie slice'.
Returns TRUE on success or FALSE on failure.
Example #1 Creating a 3D looking pie
<?php
// create image
$image = imagecreatetruecolor(100, 100);
// allocate some colors
$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$gray = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
$darkgray = imagecolorallocate($image, 0x90, 0x90, 0x90);
$navy = imagecolorallocate($image, 0x00, 0x00, 0x80);
$darknavy = imagecolorallocate($image, 0x00, 0x00, 0x50);
$red = imagecolorallocate($image, 0xFF, 0x00, 0x00);
$darkred = imagecolorallocate($image, 0x90, 0x00, 0x00);
// make the 3D effect
for ($i = 60; $i > 50; $i--) {
imagefilledarc($image, 50, $i, 100, 50, 0, 45, $darknavy, IMG_ARC_PIE);
imagefilledarc($image, 50, $i, 100, 50, 45, 75 , $darkgray, IMG_ARC_PIE);
imagefilledarc($image, 50, $i, 100, 50, 75, 360 , $darkred, IMG_ARC_PIE);
}
imagefilledarc($image, 50, 50, 100, 50, 0, 45, $navy, IMG_ARC_PIE);
imagefilledarc($image, 50, 50, 100, 50, 45, 75 , $gray, IMG_ARC_PIE);
imagefilledarc($image, 50, 50, 100, 50, 75, 360 , $red, IMG_ARC_PIE);
// flush image
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>
The above example will output something similar to:
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
imagefilledellipse — Draw a filled ellipse
$image
, int $cx
, int $cy
, int $width
, int $height
, int $color
) : bool
Draws an ellipse centered at the specified coordinate on the given
image.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
cxx-coordinate of the center.
cyy-coordinate of the center.
widthThe ellipse width.
heightThe ellipse height.
colorThe fill color. A color identifier created with imagecolorallocate().
Returns TRUE on success or FALSE on failure.
Example #1 imagefilledellipse() example
<?php
// create a blank image
$image = imagecreatetruecolor(400, 300);
// fill the background color
$bg = imagecolorallocate($image, 0, 0, 0);
// choose a color for the ellipse
$col_ellipse = imagecolorallocate($image, 255, 255, 255);
// draw the white ellipse
imagefilledellipse($image, 200, 150, 300, 200, $col_ellipse);
// output the picture
header("Content-type: image/png");
imagepng($image);
?>
The above example will output something similar to:
Note:
imagefilledellipse() ignores imagesetthickness().
(PHP 4, PHP 5, PHP 7)
imagefilledpolygon — Draw a filled polygon
$image
, array $points
, int $num_points
, int $color
) : bool
imagefilledpolygon() creates a filled polygon
in the given image.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
points
An array containing the x and y
coordinates of the polygons vertices consecutively.
num_pointsTotal number of points (vertices), which must be at least 3.
colorA color identifier created with imagecolorallocate().
Returns TRUE on success or FALSE on failure.
Example #1 imagefilledpolygon() example
<?php
// set up array of points for polygon
$values = array(
40, 50, // Point 1 (x, y)
20, 240, // Point 2 (x, y)
60, 60, // Point 3 (x, y)
240, 20, // Point 4 (x, y)
50, 40, // Point 5 (x, y)
10, 10 // Point 6 (x, y)
);
// create image
$image = imagecreatetruecolor(250, 250);
// allocate colors
$bg = imagecolorallocate($image, 0, 0, 0);
$blue = imagecolorallocate($image, 0, 0, 255);
// fill the background
imagefilledrectangle($image, 0, 0, 249, 249, $bg);
// draw a polygon
imagefilledpolygon($image, $values, 6, $blue);
// flush image
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>
The above example will output something similar to:
(PHP 4, PHP 5, PHP 7)
imagefilledrectangle — Draw a filled rectangle
$image
, int $x1
, int $y1
, int $x2
, int $y2
, int $color
) : bool
Creates a rectangle filled with color in the given
image starting at point 1 and ending at point 2.
0, 0 is the top left corner of the image.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
x1x-coordinate for point 1.
y1y-coordinate for point 1.
x2x-coordinate for point 2.
y2y-coordinate for point 2.
colorThe fill color. A color identifier created with imagecolorallocate().
Returns TRUE on success or FALSE on failure.
Example #1 imagefilledrectangle() usage
<?php
// Create a 55x30 image
$im = imagecreatetruecolor(55, 30);
$white = imagecolorallocate($im, 255, 255, 255);
// Draw a white rectangle
imagefilledrectangle($im, 4, 4, 50, 25, $white);
// Save the image
imagepng($im, './imagefilledrectangle.png');
imagedestroy($im);
?>
The above example will output something similar to:
(PHP 4, PHP 5, PHP 7)
imagefilltoborder — Flood fill to specific color
$image
, int $x
, int $y
, int $border
, int $color
) : bool
imagefilltoborder() performs a flood fill
whose border color is defined by border.
The starting point for the fill is x,
y (top left is 0, 0) and the region is
filled with color color.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
xx-coordinate of start.
yy-coordinate of start.
borderThe border color. A color identifier created with imagecolorallocate().
colorThe fill color. A color identifier created with imagecolorallocate().
Returns TRUE on success or FALSE on failure.
Example #1 Filling an ellipse with a color
<?php
// Create the image handle, set the background to white
$im = imagecreatetruecolor(100, 100);
imagefilledrectangle($im, 0, 0, 100, 100, imagecolorallocate($im, 255, 255, 255));
// Draw an ellipse to fill with a black border
imageellipse($im, 50, 50, 50, 50, imagecolorallocate($im, 0, 0, 0));
// Set the border and fill colors
$border = imagecolorallocate($im, 0, 0, 0);
$fill = imagecolorallocate($im, 255, 0, 0);
// Fill the selection
imagefilltoborder($im, 50, 50, $border, $fill);
// Output and free memory
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
The above example will output something similar to:
(PHP 5, PHP 7)
imagefilter — Applies a filter to an image
$image
, int $filtertype
[, int $arg1
[, int $arg2
[, int $arg3
[, int $arg4
]]]] ) : bool
imagefilter() applies the given filter
filtertype on the image.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
filtertype
filtertype can be one of the following:
IMG_FILTER_NEGATE: Reverses all colors of
the image.
IMG_FILTER_GRAYSCALE: Converts the image into
grayscale by changing the red, green and blue components to their
weighted sum using the same coefficients as the REC.601 luma (Y')
calculation. The alpha components are retained. For palette images the
result may differ due to palette limitations.
IMG_FILTER_BRIGHTNESS: Changes the brightness
of the image. Use arg1 to set the level of
brightness. The range for the brightness is -255 to 255.
IMG_FILTER_CONTRAST: Changes the contrast of
the image. Use arg1 to set the level of
contrast.
IMG_FILTER_COLORIZE: Like
IMG_FILTER_GRAYSCALE, except you can specify the
color. Use arg1, arg2 and
arg3 in the form of
red, green,
blue and arg4 for the
alpha channel. The range for each color is 0 to 255.
IMG_FILTER_EDGEDETECT: Uses edge detection to
highlight the edges in the image.
IMG_FILTER_EMBOSS: Embosses the image.
IMG_FILTER_GAUSSIAN_BLUR: Blurs the image using
the Gaussian method.
IMG_FILTER_SELECTIVE_BLUR: Blurs the image.
IMG_FILTER_MEAN_REMOVAL: Uses mean removal to
achieve a "sketchy" effect.
IMG_FILTER_SMOOTH: Makes the image smoother.
Use arg1 to set the level of smoothness.
IMG_FILTER_PIXELATE: Applies pixelation effect
to the image, use arg1 to set the block size
and arg2 to set the pixelation effect mode.
IMG_FILTER_SCATTER: Applies scatter effect
to the image, use arg1 and
arg2 to define the effect strength and
additionally arg3 to only apply the
on select pixel colors.
arg1
IMG_FILTER_BRIGHTNESS: Brightness level.
IMG_FILTER_CONTRAST: Contrast level.
IMG_FILTER_COLORIZE: Value of red component.
IMG_FILTER_SMOOTH: Smoothness level.
IMG_FILTER_PIXELATE: Block size in pixels.
IMG_FILTER_SCATTER: Effect substraction level.
This must not be higher or equal to the addition level set with
arg2.
arg2
IMG_FILTER_COLORIZE: Value of green component.
IMG_FILTER_PIXELATE: Whether to use advanced pixelation
effect or not (defaults to FALSE).
IMG_FILTER_SCATTER: Effect addition level.
arg3
IMG_FILTER_COLORIZE: Value of blue component.
IMG_FILTER_SCATTER: Optional array indexed color values
to apply effect at.
arg4
IMG_FILTER_COLORIZE: Alpha channel, A value
between 0 and 127. 0 indicates completely opaque while 127 indicates
completely transparent.
Returns TRUE on success or FALSE on failure.
| Version | Description |
|---|---|
| 7.4.0 |
Scatter support (IMG_FILTER_SCATTER) was added.
|
| 5.3.0 |
Pixelation support (IMG_FILTER_PIXELATE) was added.
|
| 5.2.5 |
Alpha support for IMG_FILTER_COLORIZE was added.
|
Example #1 imagefilter() grayscale example
<?php
$im = imagecreatefrompng('dave.png');
if($im && imagefilter($im, IMG_FILTER_GRAYSCALE))
{
echo 'Image converted to grayscale.';
imagepng($im, 'dave.png');
}
else
{
echo 'Conversion to grayscale failed.';
}
imagedestroy($im);
?>
Example #2 imagefilter() brightness example
<?php
$im = imagecreatefrompng('sean.png');
if($im && imagefilter($im, IMG_FILTER_BRIGHTNESS, 20))
{
echo 'Image brightness changed.';
imagepng($im, 'sean.png');
imagedestroy($im);
}
else
{
echo 'Image brightness change failed.';
}
?>
Example #3 imagefilter() colorize example
<?php
$im = imagecreatefrompng('philip.png');
/* R, G, B, so 0, 255, 0 is green */
if($im && imagefilter($im, IMG_FILTER_COLORIZE, 0, 255, 0))
{
echo 'Image successfully shaded green.';
imagepng($im, 'philip.png');
imagedestroy($im);
}
else
{
echo 'Green shading failed.';
}
?>
Example #4 imagefilter() negate example
<?php
// Define our negate function so its portable for
// php versions without imagefilter()
function negate($im)
{
if(function_exists('imagefilter'))
{
return imagefilter($im, IMG_FILTER_NEGATE);
}
for($x = 0; $x < imagesx($im); ++$x)
{
for($y = 0; $y < imagesy($im); ++$y)
{
$index = imagecolorat($im, $x, $y);
$rgb = imagecolorsforindex($index);
$color = imagecolorallocate($im, 255 - $rgb['red'], 255 - $rgb['green'], 255 - $rgb['blue']);
imagesetpixel($im, $x, $y, $color);
}
}
return(true);
}
$im = imagecreatefromjpeg('kalle.jpg');
if($im && negate($im))
{
echo 'Image successfully converted to negative colors.';
imagejpeg($im, 'kalle.jpg', 100);
imagedestroy($im);
}
else
{
echo 'Converting to negative colors failed.';
}
?>
Example #5 imagefilter() pixelate example
<?php
// Load the PHP logo, we need to create two instances
// to show the differences
$logo1 = imagecreatefrompng('./php.png');
$logo2 = imagecreatefrompng('./php.png');
// Create the image instance we want to show the
// differences on
$output = imagecreatetruecolor(imagesx($logo1) * 2, imagesy($logo1));
// Apply pixelation to each instance, with a block
// size of 3
imagefilter($logo1, IMG_FILTER_PIXELATE, 3);
imagefilter($logo2, IMG_FILTER_PIXELATE, 3, true);
// Merge the differences onto the output image
imagecopy($output, $logo1, 0, 0, 0, 0, imagesx($logo1) - 1, imagesy($logo1) - 1);
imagecopy($output, $logo2, imagesx($logo2), 0, 0, 0, imagesx($logo2) - 1, imagesy($logo2) - 1);
imagedestroy($logo1);
imagedestroy($logo2);
// Output the differences
header('Content-Type: image/png');
imagepng($output);
imagedestroy($output);
?>
The above example will output something similar to:
Example #6 imagefilter() scatter example
<?php
// Load the image
$logo = imagecreatefrompng('./php.png');
// Apply a very soft scatter effect to the image
imagefilter($logo, IMG_FILTER_SCATTER, 3, 5);
// Output the image with the scatter effect
header('Content-Type: image/png');
imagepng($logo);
imagedestroy($logo);
?>
The above example will output something similar to:
Note: The result of
IMG_FILTER_SCATTERis always random.
(PHP 5 >= 5.5.0, PHP 7)
imageflip — Flips an image using a given mode
$image
, int $mode
) : bool
Flips the image image using the given
mode.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
mode
Flip mode, this can be one of the IMG_FLIP_* constants:
| Constant | Meaning |
|---|---|
IMG_FLIP_HORIZONTAL |
Flips the image horizontally. |
IMG_FLIP_VERTICAL |
Flips the image vertically. |
IMG_FLIP_BOTH |
Flips the image both horizontally and vertically. |
Returns TRUE on success or FALSE on failure.
Example #1 Flips an image vertically
This example uses the IMG_FLIP_VERTICAL
constant.
<?php
// File
$filename = 'phplogo.png';
// Content type
header('Content-type: image/png');
// Load
$im = imagecreatefrompng($filename);
// Flip it vertically
imageflip($im, IMG_FLIP_VERTICAL);
// Output
imagejpeg($im);
imagedestroy($im);
?>
The above example will output something similar to:
Example #2 Flips the image horizontally
This example uses the IMG_FLIP_HORIZONTAL constant.
<?php
// File
$filename = 'phplogo.png';
// Content type
header('Content-type: image/png');
// Load
$im = imagecreatefrompng($filename);
// Flip it horizontally
imageflip($im, IMG_FLIP_HORIZONTAL);
// Output
imagejpeg($im);
imagedestroy($im);
?>
The above example will output something similar to:
(PHP 4, PHP 5, PHP 7)
imagefontheight — Get font height
$font
) : intReturns the pixel height of a character in the specified font.
fontCan be 1, 2, 3, 4, 5 for built-in fonts in latin2 encoding (where higher numbers corresponding to larger fonts) or any of your own font identifiers registered with imageloadfont().
Returns the pixel height of the font.
Example #1 Using imagefontheight() on built-in fonts
<?php
echo 'Font height: ' . imagefontheight(4);
?>
The above example will output something similar to:
Font height: 16
Example #2 Using imagefontheight() together with imageloadfont()
<?php
// Load a .gdf font
$font = imageloadfont('anonymous.gdf');
echo 'Font height: ' . imagefontheight($font);
?>
The above example will output something similar to:
Font height: 43
(PHP 4, PHP 5, PHP 7)
imagefontwidth — Get font width
$font
) : intReturns the pixel width of a character in font.
fontCan be 1, 2, 3, 4, 5 for built-in fonts in latin2 encoding (where higher numbers corresponding to larger fonts) or any of your own font identifiers registered with imageloadfont().
Returns the pixel width of the font.
Example #1 Using imagefontwidth() on built-in fonts
<?php
echo 'Font width: ' . imagefontwidth(4);
?>
The above example will output something similar to:
Font width: 8
Example #2 Using imagefontwidth() together with imageloadfont()
<?php
// Load a .gdf font
$font = imageloadfont('anonymous.gdf');
echo 'Font width: ' . imagefontwidth($font);
?>
The above example will output something similar to:
Font width: 23
(PHP 4 >= 4.0.7, PHP 5, PHP 7)
imageftbbox — Give the bounding box of a text using fonts via freetype2
$size
, float $angle
, string $fontfile
, string $text
[, array $extrainfo
] ) : arrayThis function calculates and returns the bounding box in pixels for a FreeType text.
Note:
imageftbbox() is an extended variant of imagettfbbox() which additionally supports the
extrainfo.
sizeThe font size in points.
angle
Angle in degrees in which text will be
measured.
fontfileThe name of the TrueType font file (can be a URL). Depending on which version of the GD library that PHP is using, it may attempt to search for files that do not begin with a leading '/' by appending '.ttf' to the filename and searching along a library-defined font path.
textThe string to be measured.
extrainfo
| Key | Type | Meaning |
|---|---|---|
linespacing |
float | Defines drawing linespacing |
imageftbbox() returns an array with 8 elements representing four points making the bounding box of the text:
| 0 | lower left corner, X position |
| 1 | lower left corner, Y position |
| 2 | lower right corner, X position |
| 3 | lower right corner, Y position |
| 4 | upper right corner, X position |
| 5 | upper right corner, Y position |
| 6 | upper left corner, X position |
| 7 | upper left corner, Y position |
The points are relative to the text regardless of the
angle, so "upper left" means in the top left-hand
corner seeing the text horizontally.
Example #1 imageftbbox() example
<?php
// Create a 300x150 image
$im = imagecreatetruecolor(300, 150);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
// Set the background to be white
imagefilledrectangle($im, 0, 0, 299, 299, $white);
// Path to our font file
$font = './arial.ttf';
// First we create our bounding box
$bbox = imageftbbox(10, 0, $font, 'The PHP Documentation Group');
// This is our cordinates for X and Y
$x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) - 5;
$y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5;
imagefttext($im, 10, 0, $x, $y, $black, $font, 'The PHP Documentation Group');
// Output to browser
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
Note: This function is only available if PHP is compiled with freetype support (--with-freetype-dir=DIR)
(PHP 4 >= 4.0.7, PHP 5, PHP 7)
imagefttext — Write text to the image using fonts using FreeType 2
$image
, float $size
, float $angle
, int $x
, int $y
, int $color
, string $fontfile
, string $text
[, array $extrainfo
] ) : arrayNote:
imagefttext() is an extended variant of imagettftext() which additionally supports the
extrainfo.
imageAn image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
sizeThe font size to use in points.
angleThe angle in degrees, with 0 degrees being left-to-right reading text. Higher values represent a counter-clockwise rotation. For example, a value of 90 would result in bottom-to-top reading text.
x
The coordinates given by x and
y will define the basepoint of the first
character (roughly the lower-left corner of the character). This
is different from the imagestring(), where
x and y define the
upper-left corner of the first character. For example, "top left"
is 0, 0.
yThe y-ordinate. This sets the position of the fonts baseline, not the very bottom of the character.
colorThe index of the desired color for the text, see imagecolorexact().
fontfileThe path to the TrueType font you wish to use.
Depending on which version of the GD library PHP is using, when
fontfile does not begin with a leading
/ then .ttf will be appended
to the filename and the library will attempt to search for that
filename along a library-defined font path.
When using versions of the GD library lower than 2.0.18, a space character,
rather than a semicolon, was used as the 'path separator' for different font files.
Unintentional use of this feature will result in the warning message:
Warning: Could not find/open font. For these affected versions, the
only solution is moving the font to a path which does not contain spaces.
In many cases where a font resides in the same directory as the script using it the following trick will alleviate any include problems.
<?php
// Set the enviroment variable for GD
putenv('GDFONTPATH=' . realpath('.'));
// Name the font to be used (note the lack of the .ttf extension)
$font = 'SomeFont';
?>
textText to be inserted into image.
extrainfo
| Key | Type | Meaning |
|---|---|---|
linespacing |
float | Defines drawing linespacing |
This function returns an array defining the four points of the box, starting in the lower left and moving counter-clockwise:
| 0 | lower left x-coordinate |
| 1 | lower left y-coordinate |
| 2 | lower right x-coordinate |
| 3 | lower right y-coordinate |
| 4 | upper right x-coordinate |
| 5 | upper right y-coordinate |
| 6 | upper left x-coordinate |
| 7 | upper left y-coordinate |
Example #1 imagefttext() example
<?php
// Create a 300x100 image
$im = imagecreatetruecolor(300, 100);
$red = imagecolorallocate($im, 0xFF, 0x00, 0x00);
$black = imagecolorallocate($im, 0x00, 0x00, 0x00);
// Make the background red
imagefilledrectangle($im, 0, 0, 299, 99, $red);
// Path to our ttf font file
$font_file = './arial.ttf';
// Draw the text 'PHP Manual' using font size 13
imagefttext($im, 13, 0, 105, 55, $black, $font_file, 'PHP Manual');
// Output image to the browser
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
Note: This function is only available if PHP is compiled with freetype support (--with-freetype-dir=DIR)